discoverd

package
v0.0.0-...-c283e9f Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: BSD-3-Clause Imports: 22 Imported by: 111

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = NewClient()
View Source
var EnvInstanceMeta = map[string]struct{}{
	"FLYNN_APP_ID":       {},
	"FLYNN_APP_NAME":     {},
	"FLYNN_RELEASE_ID":   {},
	"FLYNN_PROCESS_TYPE": {},
	"FLYNN_JOB_ID":       {},
}

EnvInstanceMeta are environment variables which will be automatically added to instance metadata if present.

View Source
var ErrInvalidProto = errors.New("discoverd: proto must be lowercase alphanumeric")
View Source
var ErrTimedOut = errors.New("discoverd: timed out waiting for instances")
View Source
var ErrUnsetProto = errors.New("discoverd: proto must be set")

Functions

func IsNotFound

func IsNotFound(err error) bool

Types

type Client

type Client struct {
	Logger log15.Logger
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func NewClientWithConfig

func NewClientWithConfig(config Config) *Client

func NewClientWithURL

func NewClientWithURL(url string) *Client

func (*Client) AddService

func (c *Client) AddService(name string, conf *ServiceConfig) error

func (*Client) AddServiceAndRegister

func (c *Client) AddServiceAndRegister(service, addr string) (Heartbeater, error)

func (*Client) AddServiceAndRegisterInstance

func (c *Client) AddServiceAndRegisterInstance(service string, inst *Instance) (Heartbeater, error)

func (*Client) Delete

func (c *Client) Delete(path string) error

func (*Client) Demote

func (c *Client) Demote(url string) error

func (*Client) Do

func (c *Client) Do(method string, path string, in, out interface{}, streamReq bool) (res stream.Stream, err error)

func (*Client) Get

func (c *Client) Get(path string, out interface{}) error

func (*Client) Instances

func (c *Client) Instances(service string, timeout time.Duration) ([]*Instance, error)

func (*Client) Ping

func (c *Client) Ping(url string) error

func (*Client) Promote

func (c *Client) Promote(url string) error

func (*Client) Put

func (c *Client) Put(path string, in, out interface{}) error

func (*Client) RaftAddPeer

func (c *Client) RaftAddPeer(addr string) (res dt.TargetLogIndex, err error)

func (*Client) RaftLeader

func (c *Client) RaftLeader() (res dt.RaftLeader, err error)

func (*Client) RaftPeers

func (c *Client) RaftPeers() (res []string, err error)

func (*Client) RaftRemovePeer

func (c *Client) RaftRemovePeer(addr string) error

func (*Client) Register

func (c *Client) Register(service, addr string) (Heartbeater, error)

func (*Client) RegisterInstance

func (c *Client) RegisterInstance(service string, inst *Instance) (Heartbeater, error)

func (*Client) RemoveService

func (c *Client) RemoveService(name string) error

func (*Client) Send

func (c *Client) Send(method string, path string, in, out interface{}) error

func (*Client) Service

func (c *Client) Service(name string) Service

func (*Client) Shutdown

func (c *Client) Shutdown(url string) (res dt.TargetLogIndex, err error)

func (*Client) Stream

func (c *Client) Stream(method string, path string, in, out interface{}) (stream.Stream, error)

type Config

type Config struct {
	Endpoints []string
}

type Event

type Event struct {
	Service     string       `json:"service"`
	Kind        EventKind    `json:"kind"`
	Instance    *Instance    `json:"instance,omitempty"`
	ServiceMeta *ServiceMeta `json:"service_meta,omitempty"`
}

func (*Event) String

func (e *Event) String() string

type EventKind

type EventKind uint
const (
	EventKindUp EventKind = 1 << iota
	EventKindUpdate
	EventKindDown
	EventKindLeader
	EventKindCurrent
	EventKindServiceMeta
	EventKindAll     = ^EventKind(0)
	EventKindUnknown = EventKind(0)
)

func (EventKind) Any

func (k EventKind) Any(kinds ...EventKind) bool

func (EventKind) MarshalJSON

func (k EventKind) MarshalJSON() ([]byte, error)

func (EventKind) String

func (k EventKind) String() string

func (*EventKind) UnmarshalJSON

func (k *EventKind) UnmarshalJSON(data []byte) error

type Heartbeater

type Heartbeater interface {
	SetMeta(map[string]string) error
	Close() error
	Addr() string
	SetClient(*Client)
}

func AddServiceAndRegister

func AddServiceAndRegister(service, addr string) (Heartbeater, error)

func Register

func Register(service, addr string) (Heartbeater, error)

type Instance

type Instance struct {
	// ID is unique within the service, and is currently defined as
	// Hex(MD5(Proto + "-" + Addr)) but this may change in the future.
	ID string `json:"id"`

	// Addr is the IP/port address that can be used to communicate with the
	// service. It must be valid to dial this address.
	Addr string `json:"addr"`

	// Proto is the protocol used to connect to the service, examples include:
	// tcp, udp, http, https. It must be lowercase alphanumeric.
	Proto string `json:"proto"`

	// Meta is arbitrary metadata specified when registering the instance.
	Meta map[string]string `json:"meta,omitempty"`

	// Index is the logical epoch of the initial registration of the instance.
	// It is guaranteed to be unique, greater than zero, not change as long as
	// the instance does not expire, and sort with other indexes in the order of
	// instance creation.
	Index uint64 `json:"index,omitempty"`
	// contains filtered or unexported fields
}

Instance is a single running instance of a service. It is immutable after it has been initialized.

func GetInstances

func GetInstances(service string, timeout time.Duration) ([]*Instance, error)

func (*Instance) Clone

func (inst *Instance) Clone() *Instance

func (*Instance) Equal

func (inst *Instance) Equal(other *Instance) bool

func (*Instance) Host

func (inst *Instance) Host() string

func (*Instance) Port

func (inst *Instance) Port() string

func (*Instance) Valid

func (inst *Instance) Valid() error

type LeaderType

type LeaderType string
const (
	LeaderTypeManual LeaderType = "manual"
	LeaderTypeOldest LeaderType = "oldest"
)

type Service

type Service interface {
	Leader() (*Instance, error)
	Instances() ([]*Instance, error)
	Addrs() ([]string, error)
	Leaders(chan *Instance) (stream.Stream, error)
	Watch(events chan *Event) (stream.Stream, error)
	GetMeta() (*ServiceMeta, error)
	SetMeta(*ServiceMeta) error
	SetLeader(string) error
}

func NewService

func NewService(name string) Service

type ServiceConfig

type ServiceConfig struct {
	LeaderType LeaderType `json:"leader_type"`
}

type ServiceMeta

type ServiceMeta struct {
	Data json.RawMessage `json:"data"`

	// LeaderID is the optional ID of an instance to set as a leader when
	// applying the new service metadata. It is only used for writes and is not
	// returned during reads.
	LeaderID string `json:"leader_id,omitempty"`

	// When calling SetMeta, Index is checked against the current index and the
	// set only succeeds if the index is the same. A zero index means the meta
	// does not currently exist.
	Index uint64 `json:"index"`
}

type Watch

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

Watch is a wrapper around an event stream which reconnects on error and generates any events which were missed by comparing local state to the current state returned by the server.

func NewWatch

func NewWatch() *Watch

func (*Watch) Close

func (w *Watch) Close() error

func (*Watch) Err

func (w *Watch) Err() error

func (*Watch) SetStateChannel

func (w *Watch) SetStateChannel(ch chan WatchState)

SetStateChannel sets a channel which will receive events when the watch connects to / disconnects from the server.

type WatchState

type WatchState string
const (
	WatchStateConnected    WatchState = "connected"
	WatchStateDisconnected WatchState = "disconnected"
)

Jump to

Keyboard shortcuts

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