Documentation ¶
Index ¶
- Constants
- Variables
- func Get(key string) (*client.Response, error)
- func GetServicesByName(name string) ([]string, error)
- func GetString(key string) string
- func GetValue(key string) (string, error)
- func Set(key, value string) (*client.Response, error)
- type RegistryClient
- type RegistryConfig
- type ReigistryClient
Constants ¶
const ( // TTL is a time to live // for record in etcd TTL = 30 * time.Second // KeepAlivePeriod is period of // goroutine to // refresh the record in etcd. KeepAlivePeriod = 20 * time.Second )
Variables ¶
var KeysAPI client.KeysAPI
KeysAPI etcd KeysAPI
Functions ¶
func GetServicesByName ¶
GetServicesByName get service by name
Types ¶
type RegistryClient ¶
type RegistryClient interface { // Register given service // to etcd instance Register() error // Unregister the service // from etcd. Unregister() error // ServiceByName // return the base addresses // for service instances. ServicesByName(name string) ([]string, error) }
RegistryClient is the interface for service discovery based on etcd.
type RegistryConfig ¶
type RegistryConfig struct { // EtcdEndpoints that service // registry client connects to. EtcdEndpoints []string // ServiceName is the // the name of // service in application. ServiceName string // InstanceName is the identification // for service instance. InstanceName string // BaseURL is the url // that the service is // acessible on. BaseURL string // contains filtered or unexported fields }
RegistryConfig is configuration structure for connectiong to etcd instance and identify the service.
type ReigistryClient ¶
type ReigistryClient struct { RegistryConfig EtcdKApi client.KeysAPI }
ReigistryClient structure implements the basic functionality for service registration in etcd. After the Reguster method is called, the client periodically refreshes the record about the service.
func New ¶
func New(config RegistryConfig) (*ReigistryClient, error)
New creates the EtcdRegistryClient with service paramters defined by config.
func (*ReigistryClient) Register ¶
func (e *ReigistryClient) Register() error
Register register service to configured etcd instance. Once the Register is called, the client also periodically calls the refresh goroutine.
func (*ReigistryClient) ServicesByName ¶
func (e *ReigistryClient) ServicesByName(name string) ([]string, error)
ServicesByName query the etcd instance for service nodes for service by given name.
func (*ReigistryClient) Unregister ¶
func (e *ReigistryClient) Unregister() error
Unregister removes the service instance from etcd. Once the Unregister method is called, the periodicall refresh goroutine is cancelled.