srd

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 4 Imported by: 1

README

SRD: 服务注册与发现的客户端库

English

例子

注意: 根据自己的需求,修改各个shell文件中的ip地址

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsulClient

type ConsulClient struct {
	ID           string
	Name         string
	ConsulAgent  *consul.Agent
	ConsulHealth *consul.Health
	TTL          time.Duration
	AgentReg     *consul.AgentServiceRegistration
}

func (*ConsulClient) DeRegister

func (this *ConsulClient) DeRegister(string) error

func (*ConsulClient) GetService

func (this *ConsulClient) GetService(service, tag string) ([]*ServiceEntry, error)

func (*ConsulClient) Register

func (this *ConsulClient) Register(registration *ServiceRegistration) error

func (*ConsulClient) UpdateTTL

func (this *ConsulClient) UpdateTTL(check func() (bool, error))

/////////////////// self function /////////////////////

type ServiceDiscoveryClient

type ServiceDiscoveryClient interface {
	// Get a Service from consul
	GetService(string, string) ([]*ServiceEntry, error)

	// Register a service with local agent
	Register(*ServiceRegistration) error

	// Deregister a service with local agent
	DeRegister(string) error
}

func NewConsulClient

func NewConsulClient(addr string) (ServiceDiscoveryClient, error)

NewConsul returns a Client interface for given consul address

type ServiceEntry

type ServiceEntry struct {
	Service string
	ID      string
	Addr    string
	Port    int
	Tags    []string
}

type ServiceRegistration

type ServiceRegistration struct {
	ID    string
	Name  string
	Addr  string
	Port  int
	Tag   []string
	TTL   time.Duration
	Check func() (bool, error)
}

Jump to

Keyboard shortcuts

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