Documentation
¶
Overview ¶
Package register is an interface for service discovery
Index ¶
- Constants
- Variables
- func ExtractSubValue(typ reflect.Type) string
- func ExtractValue(v reflect.Type, d int) string
- func NewContext(ctx context.Context, c Register) context.Context
- type DeregisterOption
- type DeregisterOptions
- type Event
- type EventType
- type ListOption
- type ListOptions
- type LookupOption
- type LookupOptions
- type Node
- type Option
- func Addrs(addrs ...string) Option
- func Codec(c codec.Codec) Option
- func Context(ctx context.Context) Option
- func Logger(l logger.Logger) Option
- func Meter(m meter.Meter) Option
- func Name(n string) Option
- func SetOption(k, v interface{}) Option
- func TLSConfig(t *tls.Config) Option
- func Timeout(t time.Duration) Option
- func Tracer(t tracer.Tracer) Option
- type Options
- type Register
- type RegisterOption
- type RegisterOptions
- type Result
- type Service
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
const (
// WildcardNamespace indicates any Namespace
WildcardNamespace = "*"
)
Variables ¶
var ( // DefaultRegister is the global default register DefaultRegister = NewRegister() // ErrNotFound returned when LookupService is called and no services found ErrNotFound = errors.New("service not found") // ErrWatcherStopped returned when when watcher is stopped ErrWatcherStopped = errors.New("watcher stopped") )
var DefaultNamespace = "micro"
DefaultNamespace to use if none was provided in options
Functions ¶
func ExtractSubValue ¶
ExtractSubValue exctact *Value from reflect.Type
func ExtractValue ¶
ExtractValue from reflect.Type from specified depth
Types ¶
type DeregisterOption ¶
type DeregisterOption func(*DeregisterOptions)
DeregisterOption option is used to deregister service
func DeregisterAttempts ¶
func DeregisterAttempts(t int) DeregisterOption
DeregisterAttempts specifies deregister atempts count
func DeregisterContext ¶
func DeregisterContext(ctx context.Context) DeregisterOption
DeregisterContext sets the context for deregister method
func DeregisterNamespace ¶ added in v4.1.0
func DeregisterNamespace(d string) DeregisterOption
DeregisterNamespace specifies deregister Namespace
type DeregisterOptions ¶
type DeregisterOptions struct { Context context.Context // Namespace the service was registered in Namespace string // Atempts specify max attempts for deregister Attempts int }
DeregisterOptions holds options for deregister method
func NewDeregisterOptions ¶
func NewDeregisterOptions(opts ...DeregisterOption) DeregisterOptions
NewDeregisterOptions returns options for deregister filled by opts
type Event ¶
type Event struct { // Timestamp is event timestamp Timestamp time.Time `json:"timestamp,omitempty"` // Service is register service Service *Service `json:"service,omitempty"` // ID is register id ID string `json:"id,omitempty"` // Type defines type of event Type EventType `json:"type,omitempty"` }
Event is register event
type ListOption ¶
type ListOption func(*ListOptions)
ListOption option is used to list services
func ListContext ¶
func ListContext(ctx context.Context) ListOption
ListContext specifies context for list method
func ListNamespace ¶ added in v4.1.0
func ListNamespace(d string) ListOption
ListNamespace sets the Namespace for list method
type ListOptions ¶
type ListOptions struct { // Context used to store additional options Context context.Context // Namespace to scope the request to Namespace string }
ListOptions holds the list options for list method
func NewListOptions ¶
func NewListOptions(opts ...ListOption) ListOptions
NewListOptions returns list options filled by opts
type LookupOption ¶
type LookupOption func(*LookupOptions)
LookupOption option is used to get service
func LookupContext ¶
func LookupContext(ctx context.Context) LookupOption
LookupContext sets the context for lookup method
func LookupNamespace ¶ added in v4.1.0
func LookupNamespace(d string) LookupOption
LookupNamespace sets the Namespace for lookup
type LookupOptions ¶
type LookupOptions struct { Context context.Context // Namespace to scope the request to Namespace string }
LookupOptions holds lookup options
func NewLookupOptions ¶
func NewLookupOptions(opts ...LookupOption) LookupOptions
NewLookupOptions returns lookup options filled by opts
type Node ¶
type Node struct { Metadata metadata.Metadata `json:"metadata,omitempty"` ID string `json:"id,omitempty"` Address string `json:"address,omitempty"` }
Node holds node register info
type Option ¶
type Option func(*Options)
Option func signature
type Options ¶
type Options struct { // Tracer used for tracing Tracer tracer.Tracer // Context holds external options Context context.Context // Logged used for logging Logger logger.Logger // Meter used for metrics Meter meter.Meter // TLSConfig holds tls.TLSConfig options TLSConfig *tls.Config // Name holds the name of register Name string // Addrs specifies register addrs Addrs []string // Codec used to marshal/unmarshal data in register Codec codec.Codec // Timeout specifies timeout Timeout time.Duration }
Options holds options for register
func NewOptions ¶
NewOptions returns options that filled by opts
type Register ¶
type Register interface { // Name returns register name Name() string // Init initialize register Init(...Option) error // Options returns options for register Options() Options // Connect initialize connect to register Connect(context.Context) error // Disconnect initialize discconection from register Disconnect(context.Context) error // Register service in registry Register(context.Context, *Service, ...RegisterOption) error // Deregister service from registry Deregister(context.Context, *Service, ...DeregisterOption) error // LookupService in registry LookupService(context.Context, string, ...LookupOption) ([]*Service, error) // ListServices in registry ListServices(context.Context, ...ListOption) ([]*Service, error) // Watch registry events Watch(context.Context, ...WatchOption) (Watcher, error) // String returns registry string representation String() string }
Register provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}
func FromContext ¶
FromContext get register from context
func MustContext ¶ added in v4.1.0
MustContext get register from context
func NewRegister ¶
type RegisterOption ¶
type RegisterOption func(*RegisterOptions) // nolint: golint,revive
RegisterOption option is used to register service
func RegisterAttempts ¶
func RegisterAttempts(t int) RegisterOption
RegisterAttempts specifies register atempts count
func RegisterContext ¶
func RegisterContext(ctx context.Context) RegisterOption
RegisterContext sets the register context
func RegisterNamespace ¶ added in v4.1.0
func RegisterNamespace(d string) RegisterOption
RegisterNamespace secifies register Namespace
func RegisterTTL ¶
func RegisterTTL(t time.Duration) RegisterOption
RegisterTTL specifies register ttl
type RegisterOptions ¶
type RegisterOptions struct { Context context.Context Namespace string TTL time.Duration Attempts int }
RegisterOptions holds options for register method
func NewRegisterOptions ¶
func NewRegisterOptions(opts ...RegisterOption) RegisterOptions
NewRegisterOptions returns register options struct filled by opts
type Result ¶
type Result struct { // Service holds register service Service *Service `json:"service,omitempty"` // Action holds the action Action EventType `json:"action,omitempty"` }
Result is returned by a call to Next on the watcher. Actions can be create, update, delete
type Service ¶
type Service struct { Name string `json:"name,omitempty"` Version string `json:"version,omitempty"` Nodes []*Node `json:"nodes,omitempty"` Namespace string `json:"namespace,omitempty"` }
Service holds service register info
type WatchOption ¶
type WatchOption func(*WatchOptions)
WatchOption option is used to watch service changes
func WatchContext ¶
func WatchContext(ctx context.Context) WatchOption
WatchContext sets the context for watch method
func WatchNamespace ¶ added in v4.1.0
func WatchNamespace(d string) WatchOption
WatchNamespace sets the Namespace for watch
type WatchOptions ¶
type WatchOptions struct { // Specify a service to watch // If blank, the watch is for all services Service string // Other options for implementations of the interface // can be stored in a context Context context.Context // Namespace to watch Namespace string }
WatchOptions holds watch options
func NewWatchOptions ¶
func NewWatchOptions(opts ...WatchOption) WatchOptions
NewWatchOptions returns watch options filled by opts