etcd

package
v0.0.0-...-2083224 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var KeysAPI client.KeysAPI

KeysAPI etcd KeysAPI

Functions

func Get

func Get(key string) (*client.Response, error)

Get etcd derict get a etcd response by key

func GetServicesByName

func GetServicesByName(name string) ([]string, error)

GetServicesByName get service by name

func GetString

func GetString(key string) string

GetString etcd derict get a string by key

func GetValue

func GetValue(key string) (string, error)

GetValue etcd derict get a value by key

func Set

func Set(key, value string) (*client.Response, error)

Set etcd direct set a key/value

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.

Jump to

Keyboard shortcuts

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