consul

package module
v0.0.0-...-db0a5b5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is consul client config

func NewClient

func NewClient(cli *api.Client) *Client

NewClient creates consul client

func (*Client) Deregister

func (c *Client) Deregister(_ context.Context, serviceID string) error

Deregister service by service ID

func (*Client) Register

func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enableHealthCheck bool) error

Register register service instance to consul

func (*Client) Service

func (c *Client) Service(ctx context.Context, service string, index uint64, passingOnly bool) ([]*registry.ServiceInstance, uint64, error)

Service get services from consul

type Config

type Config struct {
	*api.Config
}

Config is consul registry config

type Option

type Option func(*Registry)

Option is consul registry option.

func WithDeregisterCriticalServiceAfter

func WithDeregisterCriticalServiceAfter(interval int) Option

WithDeregisterCriticalServiceAfter with deregister-critical-service-after in seconds.

func WithHealthCheck

func WithHealthCheck(enable bool) Option

WithHealthCheck with registry health check option.

func WithHealthCheckInterval

func WithHealthCheckInterval(interval int) Option

WithHealthCheckInterval with healthcheck interval in seconds.

func WithHeartbeat

func WithHeartbeat(enable bool) Option

WithHeartbeat enable or disable heartbeat

func WithServiceResolver

func WithServiceResolver(fn ServiceResolver) Option

WithServiceResolver with endpoint function option.

type Registry

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

Registry is consul registry

func New

func New(apiClient *api.Client, opts ...Option) *Registry

New creates consul registry

func (*Registry) Deregister

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

Deregister deregister service

func (*Registry) GetService

func (r *Registry) GetService(ctx context.Context, name string) (services []*registry.ServiceInstance, err error)

GetService return service by name

func (*Registry) GetServiceList

func (r *Registry) GetServiceList(ctx context.Context) ([]*registry.ServiceInstance, error)

func (*Registry) ListServices

func (r *Registry) ListServices() (allServices map[string][]*registry.ServiceInstance, err error)

ListServices return service list.

func (*Registry) Register

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

Register register service

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, name string) (registry.Watcher, error)

Watch resolve service by name

type ServiceResolver

type ServiceResolver func(ctx context.Context, entries []*api.ServiceEntry) []*registry.ServiceInstance

ServiceResolver is used to resolve service endpoints

Jump to

Keyboard shortcuts

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