Documentation ¶
Index ¶
- type Client
- func (c *Client) CreateRegister(conf *RegistryConfig) (*Register, error)
- func (c *Client) DelKV(key string, index uint64) (bool, error)
- func (c *Client) GetHealthService(service, tag string, passingOnly bool, waitIndex uint64) ([]*api.ServiceEntry, uint64, error)
- func (c *Client) GetHealthState(state string, waitIndex uint64) (api.HealthChecks, uint64, error)
- func (c *Client) GetKV(key string, waitIndex uint64) ([]byte, uint64, error)
- func (c *Client) GetService(service, tag string, waitIndex uint64) ([]*api.CatalogService, uint64, error)
- func (c *Client) GetServices(waitIndex uint64) (map[string][]string, uint64, error)
- func (c *Client) ListKV(path string, waitIndex uint64) (map[string][]byte, uint64, error)
- func (c *Client) LoadKV(path string, waitIndex uint64, loader loader.Loader) (uint64, error)
- func (c *Client) LoadListKV(path string, waitIndex uint64, loader loader.Loaders) (uint64, error)
- func (c *Client) PutKV(key, value string, index uint64) (bool, error)
- func (c *Client) WatchKV(key string, loader loader.Loader, immediately bool) error
- func (c *Client) WatchListKV(path string, loader loader.Loaders, immediately bool) error
- func (c *Client) WatchServiceServices(service, tag string, fun func(infos []*RegistryInfo))
- func (c *Client) WatchServiceServices2(service, tag string, fun func(addInfos, delInfos []*RegistryInfo))
- func (c *Client) WatchServices(tag string, fun func(infos []*RegistryInfo))
- func (c *Client) WatchServices2(tag string, fun func(addInfos, delInfos []*RegistryInfo))
- type Register
- type RegistryConfig
- type RegistryInfo
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 ¶
CreateClient 创建 addr:Consul地址 scheme:连接consul协议
func DefaultClient ¶
func DefaultClient() *Client
func InitDefaultClient ¶
func (*Client) CreateRegister ¶
func (c *Client) CreateRegister(conf *RegistryConfig) (*Register, error)
CreateRegister 创建注册对象
func (*Client) GetHealthService ¶
func (c *Client) GetHealthService(service, tag string, passingOnly bool, waitIndex uint64) ([]*api.ServiceEntry, uint64, error)
GetHealthService 获取某个服务的所有的服务节点
func (*Client) GetHealthState ¶
GetHealthState 获取状态为state的所有的服务节点 state取值 any(api.HealthAny) passing warning critical maintenance
func (*Client) GetService ¶
func (c *Client) GetService(service, tag string, waitIndex uint64) ([]*api.CatalogService, uint64, error)
GetService 获取服务器组下的服务节点
func (*Client) GetServices ¶
GetServices 获取服务器组和服务器组下的tag
func (*Client) LoadListKV ¶
LoadListKV 调用ListKV并加载配置
func (*Client) WatchKV ¶
WatchKV 监控key配置 immediately是否先同步获取一次配置 watch后的key不允许删除,就是说这个key要求一只存在,否则一只会尝试加载
func (*Client) WatchListKV ¶
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注册对象
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 服务注册信息