consul

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 13 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 consul对象 https://developer.hashicorp.com/consul/api-docs

func CreateClient

func CreateClient(addr, scheme string) (*Client, error)

CreateClient 创建 addr:Consul地址 scheme:连接consul协议

func DefaultClient

func DefaultClient() *Client

func InitDefaultClient

func InitDefaultClient(addr, scheme string) (*Client, error)

func (*Client) CreateRegister

func (c *Client) CreateRegister(conf *RegistryConfig) (*Register, error)

CreateRegister 创建注册对象

func (*Client) DelKV

func (c *Client) DelKV(key string, index uint64) (bool, error)

DelKV 删除key

func (*Client) GetHealthService

func (c *Client) GetHealthService(service, tag string, passingOnly bool, waitIndex uint64) ([]*api.ServiceEntry, uint64, error)

GetHealthService 获取某个服务的所有的服务节点

func (*Client) GetHealthState

func (c *Client) GetHealthState(state string, waitIndex uint64) (api.HealthChecks, uint64, error)

GetHealthState 获取状态为state的所有的服务节点 state取值 any(api.HealthAny) passing warning critical maintenance

func (*Client) GetKV

func (c *Client) GetKV(key string, waitIndex uint64) ([]byte, uint64, error)

GetKV 获取key对应的value

func (*Client) GetService

func (c *Client) GetService(service, tag string, waitIndex uint64) ([]*api.CatalogService, uint64, error)

GetService 获取服务器组下的服务节点

func (*Client) GetServices

func (c *Client) GetServices(waitIndex uint64) (map[string][]string, uint64, error)

GetServices 获取服务器组和服务器组下的tag

func (*Client) ListKV

func (c *Client) ListKV(path string, waitIndex uint64) (map[string][]byte, uint64, error)

ListKV 列出path下的所有KV

func (*Client) LoadKV

func (c *Client) LoadKV(path string, waitIndex uint64, loader loader.Loader) (uint64, error)

LoadKV 调用GetKV并加载配置

func (*Client) LoadListKV

func (c *Client) LoadListKV(path string, waitIndex uint64, loader loader.Loaders) (uint64, error)

LoadListKV 调用ListKV并加载配置

func (*Client) PutKV

func (c *Client) PutKV(key, value string, index uint64) (bool, error)

PutKV 写key对应的value值

func (*Client) WatchKV

func (c *Client) WatchKV(key string, loader loader.Loader, immediately bool) error

WatchKV 监控key配置 immediately是否先同步获取一次配置 watch后的key不允许删除,就是说这个key要求一只存在,否则一只会尝试加载

func (*Client) WatchListKV

func (c *Client) WatchListKV(path string, loader loader.Loaders, immediately bool) error

WatchListKV 监控path路径下的多个配置 immediately是否先同步获取一次配置

func (*Client) WatchServiceServices

func (c *Client) WatchServiceServices(service, tag string, fun func(infos []*RegistryInfo))

WatchServiceServices 监控具体分组的服务器变化 RegistryConfig值填充Registry前缀的变量 回调外部不要修改infos参数

func (*Client) WatchServiceServices2

func (c *Client) WatchServiceServices2(service, tag string, fun func(addInfos, delInfos []*RegistryInfo))

WatchServiceServices 监控具体分组的服务器变化 RegistryConfig值填充Registry前缀的变量 回调外部不要修改addInfos delInfos参数

func (*Client) WatchServices

func (c *Client) WatchServices(tag string, fun func(infos []*RegistryInfo))

WatchService 监控服务器变化 RegistryConfig值填充Registry前缀的变量 回调外部不要修改infos参数

func (*Client) WatchServices2

func (c *Client) WatchServices2(tag string, fun func(addInfos, delInfos []*RegistryInfo))

WatchServices2 监控服务器变化 RegistryConfig值填充Registry前缀的变量 回调外部不要修改addInfos delInfos参数

type Register

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

Register consul注册对象

func (*Register) DeReg

func (r *Register) DeReg() error

DeReg 注销

func (*Register) Reg

func (r *Register) Reg() error

Reg 向配置中心注册 默认注册会自动开启健康检查的端口监听 若RegistryMeta中有 "healthListenNo":"yes" 配置将不会开启健康检查的端口监听 若RegistryMeta中有 "healthListenReuse":"yes" 开启健康检查的端口监听采用复用的方式

type RegistryConfig

type RegistryConfig struct {
	RegistryName string            `json:"registryname,omitempty"` // 注册的名字 组名
	RegistryID   string            `json:"registryid,omitempty"`   // 注册的ID
	RegistryAddr string            `json:"registryaddr,omitempty"` // 服务器对外暴露的地址
	RegistryPort int               `json:"registryport,omitempty"` // 服务器对外暴露的端口
	RegistryTag  []string          `json:"registrytag,omitempty"`  // 注册的Tag
	RegistryMeta map[string]string `json:"registrymeta,omitempty"` // 注册的Meta,单个Value长度限制是512个字符

	HealthPort     int    `json:"healthport,omitempty"`     // 健康检查端口
	HealthPath     string `json:"healthpath,omitempty"`     // 健康检查路径 以/开头
	HealthInterval int    `json:"healthinterval,omitempty"` // 健康检查间隔 单位秒
	HealthTimeout  int    `json:"healthtimeout,omitempty"`  // 健康检查超时时间 单位秒
	DeregisterTime int    `json:"deregistertime,omitempty"` // 健康检查失败后 多长时间自动取消注册 貌似最小值是60s 单位秒
}

RegistryConfig 服务注册配置

type RegistryInfo

type RegistryInfo struct {
	RegistryName string            `json:"registryname,omitempty"` // 注册的名字 组名
	RegistryID   string            `json:"registryid,omitempty"`   // 注册的ID
	RegistryAddr string            `json:"registryaddr,omitempty"` // 服务器对外暴露的地址
	RegistryPort int               `json:"registryport,omitempty"` // 服务器对外暴露的端口
	RegistryTag  []string          `json:"registrytag,omitempty"`  // 注册的Tag
	RegistryMeta map[string]string `json:"registrymeta,omitempty"` // 注册的Meta,单个Value长度限制是512个字符
}

RegistryInfo 服务注册信息

Jump to

Keyboard shortcuts

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