Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultEtcdAddresses used when no custom *etcd.Client is given DefaultEtcdAddresses = []string{`http://localhost:2379`} // DefaultClusterPrefix is using geertjohan.net to avoid collision. Chances are tiny anyone else will use this key. DefaultClusterPrefix = `/geertjohan.net/aerospike-discovery/default` // DefaultLogger discards logs DefaultLogger = log.New(ioutil.Discard, ``, 0) // DefaultAnnouncerConfig is used by NewAnnouncer when no custom *AnnouncerConfig is given. DefaultAnnouncerConfig = &AnnouncerConfig{ TTL: 60, Interval: 45, } // DefaultWatcherConfig is used by NewWatcher when no custom *WatcherConfig is given DefaultWatcherConfig = &WatcherConfig{} )
var ( // ErrWatcherClosed is returned by (*Watcher).Next() when the Watcher was closed. ErrWatcherClosed = errors.New("watcher is closed") )
Functions ¶
This section is empty.
Types ¶
type Announcement ¶
type Announcement struct { Key string `json:"-"` IP string `json:"ip"` ServicePort uint16 `json:"servicePort"` MeshPort uint16 `json:"meshPort"` }
Announcement contains information about a single node in an Aerospike cluster. The Announcement is marshalled to json and stored in etcd.
type Announcer ¶
type Announcer struct {
// contains filtered or unexported fields
}
Announcer announces a node at regular intervals.
func NewAnnouncer ¶
func NewAnnouncer(announcement *Announcement, config *AnnouncerConfig) (*Announcer, error)
NewAnnouncer starts and returns a new Announcer instance. When AnnouncerConfig is nil, DefaultAnnouncerConfig is used. An announcer announces a single aerospike node at regular intervals, for this a goroutine is started. Use the Stop method to stop announcing.
type AnnouncerConfig ¶
type AnnouncerConfig struct { // EtcdClient to use in announcement calls. // When nil, a new client with address http://localhost:2379 is used. // An etcd.Client should only be used once as it is not goroutine safe. EtcdClient *etcd.Client // ClusterPrefix to use in the etcd keys ClusterPrefix string // TTL and Interval for the announcement TTL uint64 Interval uint64 // Logger for debug/info logs. // When nil, logs are discarded. Logger *log.Logger }
AnnouncerConfig can be used to modify the Announcer behaviour.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches aerospike-discovery announcements. The creator must either continiously receive from the Announcements channel or close the Watcher.
func NewWatcher ¶
func NewWatcher(config *WatcherConfig) *Watcher
NewWatcher starts a new watcher. The config argument can be nil, in which case DefaultWatcherConfig will be used. Read all announcements and their updates by calling the Next() method.
func (*Watcher) Next ¶
func (w *Watcher) Next() (*Announcement, error)
Next gives a new announcement or an update to an announcement that was returned by Next() earlier. When an error occurred during watching, that error is returned. When the Watcher was closed, ErrWatcherClosed is returned.
type WatcherConfig ¶
type WatcherConfig struct { // EtcdClient for Get and Watch calls. When nil a new etcd.Client is created with DefaultEtcdAddress as path. EtcdClient *etcd.Client // ClusterPrefix used in the etcd keys. DefaultClusterPrefix is used when empty. ClusterPrefix string // Logger to send info/debug logs on. When nil the DefaultLogger is used. Logger *log.Logger }
WatcherConfig can be used to pass custom settings to NewWatcher