consul

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: MIT Imports: 11 Imported by: 0

README

consul

kratos 项目实现的基于 consul 的服务发现代码逻辑有些问题,自己实现一套。

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 deregister service by service ID

func (*Client) ListServices

func (c *Client) ListServices(ctx context.Context) ([]*registry.ServiceInstance, error)

ListServices get services from consul

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, passingOnly bool) ([]*registry.ServiceInstance, 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 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) ListServices

func (r *Registry) ListServices(ctx context.Context) (allServices []*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