client

package
v0.0.0-...-dd72184 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by GetMount when an object does not exist.

Functions

func NewDecoder

func NewDecoder(w WatchableConfig) watcher.Watchable

NewDecoder decodes mount protobufs and converts a WatchableConfig to a watcher.Watchable.

func WatchConfig

func WatchConfig(ctx context.Context, cli *clientv3.Client, target WatchableConfig) (<-chan struct{}, <-chan struct{})

WatchConfig monitors a WatchableConfig object and keeps it in sync with etcd. The outer Context is used for termination. Returns the WaitForInit() and Notify() channels so the client can know when the configuration is bootstrapped and changes.

The simplest, read-only configuration management looks like this:

var config client.MountConfig
ready, _ := client.WatchConfig(ctx, etcdClient, &config)
<-ready

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

The Client manipulates the autoradio stream configuration by talking directly to etcd.

func New

func New(cli *clientv3.Client) *Client

New returns a new Client.

func (*Client) DeleteMount

func (c *Client) DeleteMount(ctx context.Context, path string) error

DeleteMount deletes a mountpoint.

func (*Client) GetMount

func (c *Client) GetMount(ctx context.Context, path string) (*pb.Mount, error)

GetMount returns data on a specific mountpoint.

func (*Client) ListMounts

func (c *Client) ListMounts(ctx context.Context) ([]*pb.Mount, error)

ListMounts returns a list of all mountpoints.

func (*Client) SetMount

func (c *Client) SetMount(ctx context.Context, m *pb.Mount) error

SetMount creates or updates an existing mountpoint.

type MountConfig

type MountConfig struct {
	// contains filtered or unexported fields
}

MountConfig is a container of mountpoints, representing the entirety of the autoradio database-backed configuration. It implements the WatchableConfig interface.

func (*MountConfig) Delete

func (mc *MountConfig) Delete(path string)

Delete a mount. Implements the WatchableConfig interface.

func (*MountConfig) GetMount

func (mc *MountConfig) GetMount(path string) (*pb.Mount, bool)

GetMount returns a specific mount, with map-like semantics.

func (*MountConfig) GetMounts

func (mc *MountConfig) GetMounts() []*pb.Mount

GetMounts returns the list of all mounts.

func (*MountConfig) Reset

func (mc *MountConfig) Reset(mounts map[string]*pb.Mount)

Reset the container with new values. Implements the WatchableConfig interface.

func (*MountConfig) Set

func (mc *MountConfig) Set(m *pb.Mount)

Set a new mount config or update an existing one. Implements the WatchableConfig interface.

type WatchableConfig

type WatchableConfig interface {
	Reset(map[string]*pb.Mount)
	Set(*pb.Mount)
	Delete(string)
}

WatchableConfig mimics the watcher.Watchable interface, but with the decoded protobufs. This allows injecting middleware to the configuration state management, to implement custom notification protocols.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL