consul

package module
v0.0.0-...-191046f Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 26 Imported by: 8

Documentation

Overview

Package consul provides the consul registry for go-orb.

Index

Constants

View Source
const Name = "consul"

Name provides the name of this registry.

Variables

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

func WithAddress(n ...string) registry.Option

WithAddress sets the Consul server addresses.

func WithAllowStale

func WithAllowStale(n bool) registry.Option

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

func WithConnect(n bool) registry.Option

WithConnect defines if services should be registered as Consul Connect services.

func WithConsulConfig

func WithConsulConfig(n *consul.Config) registry.Option

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

func WithSecure(n bool) registry.Option

WithSecure defines if we want a secure connection to Consul.

func WithTCPCheck

func WithTCPCheck(t time.Duration) registry.Option

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].

[1] https://www.consul.io/docs/agent/checks.html

func WithTLSConfig

func WithTLSConfig(n *tls.Config) registry.Option

WithTLSConfig defines the TLS config to use for the secure connection.

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

func (c *Config) ApplyOptions(opts ...registry.Option)

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 New

func New(serviceName string, _ string, cfg Config, logger log.Logger) *RegistryConsul

New creates a new consul registry.

func (*RegistryConsul) Client

func (c *RegistryConsul) Client() *consul.Client

Client returns the consul client.

func (*RegistryConsul) Deregister

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) Start

func (c *RegistryConsul) Start() error

Start the registry.

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

Watch returns a Watcher which you can watch on.

Jump to

Keyboard shortcuts

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