Documentation ¶
Index ¶
- Variables
- func IsNotFound(err error) bool
- type Client
- func (c *Client) AddService(name string, conf *ServiceConfig) error
- func (c *Client) AddServiceAndRegister(service, addr string) (Heartbeater, error)
- func (c *Client) AddServiceAndRegisterInstance(service string, inst *Instance) (Heartbeater, error)
- func (c *Client) Delete(path string) error
- func (c *Client) Demote(url string) error
- func (c *Client) Do(method string, path string, in, out interface{}, streamReq bool) (res stream.Stream, err error)
- func (c *Client) Get(path string, out interface{}) error
- func (c *Client) Instances(service string, timeout time.Duration) ([]*Instance, error)
- func (c *Client) Ping(url string) error
- func (c *Client) Promote(url string) error
- func (c *Client) Put(path string, in, out interface{}) error
- func (c *Client) RaftAddPeer(addr string) (res dt.TargetLogIndex, err error)
- func (c *Client) RaftLeader() (res dt.RaftLeader, err error)
- func (c *Client) RaftPeers() (res []string, err error)
- func (c *Client) RaftRemovePeer(addr string) error
- func (c *Client) Register(service, addr string) (Heartbeater, error)
- func (c *Client) RegisterInstance(service string, inst *Instance) (Heartbeater, error)
- func (c *Client) RemoveService(name string) error
- func (c *Client) Send(method string, path string, in, out interface{}) error
- func (c *Client) Service(name string) Service
- func (c *Client) Shutdown(url string) (res dt.TargetLogIndex, err error)
- func (c *Client) Stream(method string, path string, in, out interface{}) (stream.Stream, error)
- type Config
- type Event
- type EventKind
- type Heartbeater
- type Instance
- type LeaderType
- type Service
- type ServiceConfig
- type ServiceMeta
- type Watch
- type WatchState
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = NewClient()
View Source
var EnvInstanceMeta = map[string]struct{}{
"OWO_APP_ID": {},
"OWO_APP_NAME": {},
"OWO_RELEASE_ID": {},
"OWO_PROCESS_TYPE": {},
"OWO_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 ¶
Types ¶
type Client ¶
func NewClientWithConfig ¶
func NewClientWithURL ¶
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) 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) RaftRemovePeer ¶
func (*Client) RegisterInstance ¶
func (c *Client) RegisterInstance(service string, inst *Instance) (Heartbeater, error)
func (*Client) RemoveService ¶
type Event ¶
type Event struct { Service string `json:"service"` Kind EventKind `json:"kind"` Instance *Instance `json:"instance,omitempty"` ServiceMeta *ServiceMeta `json:"service_meta,omitempty"` }
type EventKind ¶
type EventKind uint
func (EventKind) MarshalJSON ¶
func (*EventKind) UnmarshalJSON ¶
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.
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 ¶
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 (*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" )
Click to show internal directories.
Click to hide internal directories.