Documentation ¶
Overview ¶
Package registry is a component for service discovery
Index ¶
- Constants
- Variables
- type Config
- type ConfigType
- type DeregisterOption
- type DeregisterOptions
- type Endpoint
- type Event
- type EventType
- type GetOption
- type GetOptions
- type ListOption
- type ListOptions
- type MicroRegistry
- type Node
- type Option
- type ProviderFunc
- type RegisterOption
- type RegisterOptions
- type Registry
- type Result
- type Service
- type Value
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
const ComponentType = "registry"
ComponentType is the registry component type name.
Variables ¶
var ( DefaultRegistry = "mdns" DefaultTimeout = 100 )
var ( // ErrNotFound is a not found error when GetService is called. ErrNotFound = errors.New("service not found") // ErrWatcherStopped is a error when watcher is stopped. ErrWatcherStopped = errors.New("watcher stopped") )
var Plugins = container.NewMap[ProviderFunc]()
Plugins is the plugins container for registry.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Plugin string `json:"plugin,omitempty" yaml:"plugin,omitempty"` Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` Logger log.Logger `json:"logger,omitempty" yaml:"logger,omitempty"` }
Config is the configuration that can be used in a registry.
func NewConfig ¶
func NewConfig() Config
NewConfig creates a new default config to use with a registry.
func (*Config) ApplyOptions ¶
ApplyOptions applies a set of options to the config.
type ConfigType ¶
type ConfigType interface {
// contains filtered or unexported methods
}
ConfigType is used in the functional options as type to identify a registry option. It is used over a static *Config type as this way plugins can also easilty set functional options without the complication of contexts, as was done in v4. This is possible because plugins will nest the registry.Config type, and thus inherit the interface that is used to identify the registry config.
Plugin specific option example:
// WithLogger option located in the MDNS registry package. func WithLogger(logger log.Logger) registry.Option { return func(c registry.ConfigType) { // The config type used here is *mdns.Config cfg, ok := c.(*Config) if ok { cfg.Logger = logger } } }
type DeregisterOption ¶
type DeregisterOption func(*DeregisterOptions)
DeregisterOption is functional option type for the deregister config.
func DeregisterContext ¶
func DeregisterContext(ctx context.Context) DeregisterOption
DeregisterContext is the context used to deregister a service.
type DeregisterOptions ¶
DeregisterOptions are the options used to deregister services.
type Endpoint ¶
type Endpoint struct { Name string `json:"name"` Request *Value `json:"request"` Response *Value `json:"response"` Metadata map[string]string `json:"metadata"` }
Endpoint represents a service endpoint in a registry.
type Event ¶
type Event struct { // ID is registry id ID string // Type defines type of event Type EventType // Timestamp is event timestamp Timestamp time.Time // Service is registry service Service *Service }
Event is registry event.
type GetOption ¶
type GetOption func(*GetOptions)
GetOption is functional option type for the get config.
func GetContext ¶
GetContext is the context used when fetching a service.
type GetOptions ¶
GetOptions are the options used to fetch a service.
type ListOption ¶
type ListOption func(*ListOptions)
ListOption is functional option type for the list config.
func ListContext ¶
func ListContext(ctx context.Context) ListOption
ListContext is the context used when listing a service.
type ListOptions ¶
ListOptions are the options used to list services.
type MicroRegistry ¶
type MicroRegistry struct {
Registry
}
MicroRegistry is the registry type is returned when you use the dynamic registry provider that selects a registry to use based on the plugin configuration.
type Node ¶
type Node struct { ID string `json:"id"` // ip:port Address string `json:"address"` // frpc/grpc/http uvm., since v5! Scheme string `json:"scheme"` Metadata map[string]string `json:"metadata"` }
Node represents a service node in a registry. One service can be comprised of multiple nodes.
type Option ¶
type Option func(ConfigType)
Option is a functional option type for the registry.
func WithLogger ¶
WithLogger sets a specific logger to use.
func WithTimeout ¶
WithTimeout sets the default registry timeout used.
type ProviderFunc ¶
type ProviderFunc func( name types.ServiceName, data types.ConfigData, logger log.Logger, opts ...Option, ) (*MicroRegistry, error)
ProviderFunc is provider function type used by plugins to create a new registry.
type RegisterOption ¶
type RegisterOption func(*RegisterOptions)
RegisterOption is functional option type for the register config.
func RegisterContext ¶
func RegisterContext(ctx context.Context) RegisterOption
RegisterContext sets the context that is used when registering a service.
func RegisterTTL ¶
func RegisterTTL(t time.Duration) RegisterOption
RegisterTTL sets the TTL for service registration.
type RegisterOptions ¶
type RegisterOptions struct { TTL time.Duration // Other options for implementations of the interface // can be stored in a context Context context.Context }
RegisterOptions are the options used to register services.
type Registry ¶
type Registry interface { types.Component // Register registers a service within the registry. Register(*Service, ...RegisterOption) error // Deregister deregisters a service within the registry. Deregister(*Service, ...DeregisterOption) error // GetService returns a service from the registry. GetService(string, ...GetOption) ([]*Service, error) // ListServices lists services within the registry. ListServices(...ListOption) ([]*Service, error) // Watch returns a Watcher which you can watch on. Watch(...WatchOption) (Watcher, error) }
Registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}.
type Result ¶
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"` Version string `json:"version"` Metadata map[string]string `json:"metadata"` Endpoints []*Endpoint `json:"endpoints"` Nodes []*Node `json:"nodes"` }
Service represents a service in a registry.
type Value ¶
type Value struct { Name string `json:"name"` Type string `json:"type"` Values []*Value `json:"values"` }
Value is a value container used in the registry.
type WatchOption ¶
type WatchOption func(*WatchOptions)
WatchOption is functional option type for the watch config.
func WatchContext ¶
func WatchContext(ctx context.Context) WatchOption
WatchContext sets a context that is used to watch.
func WatchService ¶
func WatchService(name string) WatchOption
WatchService sets a service name to 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 }
WatchOptions are the options used by the registry watcher.