Documentation ¶
Overview ¶
Package consul provides the consul registry for go-orb.
Index ¶
- Constants
- Variables
- func ProvideRegistryConsul(name types.ServiceName, version types.ServiceVersion, datas types.ConfigData, ...) (registry.Type, error)
- func WithAddress(n ...string) registry.Option
- func WithAllowStale(n bool) registry.Option
- func WithConnect(n bool) registry.Option
- func WithConsulConfig(n *consul.Config) registry.Option
- func WithQueryOptions(n *consul.QueryOptions) registry.Option
- func WithSecure(n bool) registry.Option
- func WithTCPCheck(t time.Duration) registry.Option
- func WithTLSConfig(n *tls.Config) registry.Option
- type Config
- type RegistryConsul
- func (c *RegistryConsul) Client() *consul.Client
- func (c *RegistryConsul) Deregister(s *registry.Service, _ ...registry.DeregisterOption) error
- func (c *RegistryConsul) GetService(name string, _ ...registry.GetOption) ([]*registry.Service, error)
- func (c *RegistryConsul) ListServices(_ ...registry.ListOption) ([]*registry.Service, error)
- func (c *RegistryConsul) NodeID() string
- func (c *RegistryConsul) Register(service *registry.Service, opts ...registry.RegisterOption) error
- func (c *RegistryConsul) ServiceName() string
- func (c *RegistryConsul) ServiceVersion() string
- func (c *RegistryConsul) Start() error
- func (c *RegistryConsul) Stop(_ context.Context) error
- func (c *RegistryConsul) String() string
- func (c *RegistryConsul) Type() string
- func (c *RegistryConsul) Watch(opts ...registry.WatchOption) (registry.Watcher, error)
Constants ¶
const Name = "consul"
Name provides the name of this registry.
Variables ¶
var ( DefaultAddresses = []string{"localhost:8500"} DefaultAllowStale = true )
Defaults.
Functions ¶
func ProvideRegistryConsul ¶
func ProvideRegistryConsul( name types.ServiceName, version types.ServiceVersion, datas types.ConfigData, logger log.Logger, opts ...registry.Option, ) (registry.Type, error)
ProvideRegistryConsul creates a new Consul registry.
func WithAddress ¶
WithAddress sets the Consul server addresses.
func WithAllowStale ¶
WithAllowStale sets whether any Consul server (non-leader) can service a read. This allows for lower latency and higher throughput at the cost of potentially stale data. Works similar to Consul DNS Config option [1]. Defaults to true.
[1] https://www.consul.io/docs/agent/options.html#allow_stale
func WithConnect ¶
WithConnect defines if services should be registered as Consul Connect services.
func WithConsulConfig ¶
WithConsulConfig defines the consul config.
func WithQueryOptions ¶
func WithQueryOptions(n *consul.QueryOptions) registry.Option
WithQueryOptions specifies the QueryOptions to be used when calling Consul. See `Consul API` for more information [1].
[1] https://godoc.org/github.com/hashicorp/consul/api#QueryOptions
func WithSecure ¶
WithSecure defines if we want a secure connection to Consul.
func WithTCPCheck ¶
WithTCPCheck will tell the service provider to check the service address and port every `t` interval. It will enabled only if `t` is greater than 0. See `TCP + Interval` for more information [1].
Types ¶
type Config ¶
type Config struct { registry.Config `yaml:",inline"` Addresses []string `json:"addresses,omitempty" yaml:"addresses,omitempty"` Secure bool `json:"secure,omitempty" yaml:"secure,omitempty"` TLSConfig *tls.Config `json:"-" yaml:"-"` Connect bool `json:"connect,omitempty" yaml:"connect,omitempty"` ConsulConfig *consul.Config `json:"-" yaml:"-"` AllowStale bool `json:"allowStale,omitempty" yaml:"allowStale,omitempty"` QueryOptions *consul.QueryOptions `json:"-" yaml:"-"` TCPCheck time.Duration `json:"tcpCheck,omitempty" yaml:"tcpCheck,omitempty"` }
Config provides configuration for the consul registry.
func NewConfig ¶
func NewConfig( serviceName types.ServiceName, datas types.ConfigData, opts ...registry.Option, ) (Config, error)
NewConfig creates a new config object.
func (*Config) ApplyOptions ¶
ApplyOptions applies a set of options to the config.
type RegistryConsul ¶
type RegistryConsul struct { Address []string sync.Mutex // contains filtered or unexported fields }
RegistryConsul is the consul registry for go-orb.
func (*RegistryConsul) Client ¶
func (c *RegistryConsul) Client() *consul.Client
Client returns the consul client.
func (*RegistryConsul) Deregister ¶
func (c *RegistryConsul) Deregister(s *registry.Service, _ ...registry.DeregisterOption) error
Deregister deregisters a service within the registry.
func (*RegistryConsul) GetService ¶
func (c *RegistryConsul) GetService(name string, _ ...registry.GetOption) ([]*registry.Service, error)
GetService returns a service from the registry.
func (*RegistryConsul) ListServices ¶
func (c *RegistryConsul) ListServices(_ ...registry.ListOption) ([]*registry.Service, error)
ListServices lists services within the registry.
func (*RegistryConsul) NodeID ¶
func (c *RegistryConsul) NodeID() string
NodeID returns the ID of this service node in the registry.
func (*RegistryConsul) Register ¶
func (c *RegistryConsul) Register(service *registry.Service, opts ...registry.RegisterOption) error
Register registers a service within the registry. TODO(jochumdev): work on the nolints.
func (*RegistryConsul) ServiceName ¶
func (c *RegistryConsul) ServiceName() string
ServiceName returns the configured name of this service.
func (*RegistryConsul) ServiceVersion ¶
func (c *RegistryConsul) ServiceVersion() string
ServiceVersion returns the configured version of this service.
func (*RegistryConsul) Stop ¶
func (c *RegistryConsul) Stop(_ context.Context) error
Stop the registry.
func (*RegistryConsul) String ¶
func (c *RegistryConsul) String() string
String returns the plugin name.
func (*RegistryConsul) Type ¶
func (c *RegistryConsul) Type() string
Type returns the component type.
func (*RegistryConsul) Watch ¶
func (c *RegistryConsul) Watch(opts ...registry.WatchOption) (registry.Watcher, error)
Watch returns a Watcher which you can watch on.