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 Node
- type Option
- type ProviderFunc
- type RegisterOption
- type RegisterOptions
- type Registry
- type Result
- type Service
- type Type
- type Value
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
const ComponentType = "registry"
ComponentType is the components name.
Variables ¶
var ( // DefaultConfigSection is the section in the config to use. DefaultConfigSection = "registry" // DefaultRegistry is the default registry to use. DefaultRegistry = "mdns" // DefaultTimeout is the default timeout for the registry. 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[string, ProviderFunc]()
Plugins is the plugins container for registries.
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"`
}
Config is the configuration that can be used in a registry.
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.
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.
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.
type ListOptions ¶
ListOptions are the options used to list services.
type Node ¶
type Node struct {
ID string `json:"id"`
// ip:port
Address string `json:"address"`
// grpc/h2c/http/http3 uvm., since go-orb!
Transport string `json:"transport"`
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 WithPlugin ¶ added in v0.1.0
WithPlugin set the implementation to use.
func WithTimeout ¶
WithTimeout sets the default registry timeout used.
type ProviderFunc ¶
type ProviderFunc func( serviceName types.ServiceName, serviceVersion types.ServiceVersion, data types.ConfigData, logger log.Logger, opts ...Option, ) (Type, 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 RegisterTTL ¶
func RegisterTTL(t time.Duration) RegisterOption
RegisterTTL sets the TTL for service registration.
type RegisterOptions ¶
RegisterOptions are the options used to register services.
type Registry ¶
type Registry interface {
types.Component
// ServiceName returns types.ServiceName that has been provided to Provide().
ServiceName() string
// ServiceVersion returns types.ServiceVersion that has been provided to Provide().
ServiceVersion() string
// Register registers a service within the registry.
Register(srv *Service, opts ...RegisterOption) error
// Deregister deregisters a service within the registry.
Deregister(srv *Service, opts ...DeregisterOption) error
// GetService returns a service from the registry.
GetService(name string, opts ...GetOption) ([]*Service, error)
// ListServices lists services within the registry.
ListServices(opts ...ListOption) ([]*Service, error)
// Watch returns a Watcher which you can watch on.
Watch(opts ...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 Type ¶ added in v0.1.0
type Type struct {
Registry
}
Type is the registry type it is returned when you use ProvideRegistry which selects a registry to use based on the plugin configuration.
func Provide ¶ added in v0.1.0
func Provide( name types.ServiceName, version types.ServiceVersion, configs types.ConfigData, logger log.Logger, opts ...Option) (Type, error)
Provide is the registry provider for wire. It parses the config from "configs", fetches the "Plugin" from the config and then forwards all it's arguments to the factory which it get's from "Plugins".
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 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
}
WatchOptions are the options used by the registry watcher.