consul

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAddr                           = "127.0.0.1:8500"
	DefaultHealthCheckInterval            = 10
	DefaultDeregisterCriticalServiceAfter = 60
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*Options
	// contains filtered or unexported fields
}

Client is a consul client.

func NewClient

func NewClient(logger *zap.Logger, opts ...Option) (*Client, error)

NewClient returns a new consul client.

The default options are:

  • Addr: DefaultAddr
  • EnableHealthCheck: true
  • HealthCheckInterval: DefaultHealthCheckInterval
  • DeregisterCriticalServiceAfter: DefaultDeregisterCriticalServiceAfter
  • HeartBeat: true

func (*Client) Deregister

func (c *Client) Deregister(_ context.Context, service *registry.ServiceInstance) error

func (*Client) Register

func (c *Client) Register(_ context.Context, service *registry.ServiceInstance) (err error)

type Option added in v0.6.0

type Option func(*Options)

func WithAddr added in v0.6.0

func WithAddr(addr string) Option

WithAddr sets the address of the consul server.

func WithDeregisterCriticalServiceAfter added in v0.6.0

func WithDeregisterCriticalServiceAfter(deregisterCriticalServiceAfter int) Option

WithDeregisterCriticalServiceAfter sets the time to wait before deregister a critical service.

func WithEnableHealthCheck added in v0.6.0

func WithEnableHealthCheck(enable bool) Option

WithEnableHealthCheck enables the health check.

func WithHealthCheckInterval added in v0.6.0

func WithHealthCheckInterval(interval int) Option

WithHealthCheckInterval sets the interval of the health check.

func WithHeartBeat added in v0.6.0

func WithHeartBeat(enable bool) Option

WithHeartBeat enables the heart beat.

type Options

type Options struct {
	// Addr is the address of the consul server.
	Addr string

	// EnableHealthCheck enables the health check.
	EnableHealthCheck bool

	// HealthCheckInterval is the interval of the health check.
	HealthCheckInterval int

	// DeregisterCriticalServiceAfter is the time to wait before deregister a critical service.
	DeregisterCriticalServiceAfter int

	// HeartBeat enables the heart beat.
	HeartBeat bool
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a consul registry.

func New

func New(client *Client) *Registry

New returns a new consul registry.

func (*Registry) Deregister

func (r *Registry) Deregister(ctx context.Context, service *registry.ServiceInstance) error

Deregister a service instance.

func (*Registry) Register

func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error

Register a service instance.

Jump to

Keyboard shortcuts

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