bconsul

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionTTL session 的超时时间,主要用于在进程非正常退出后锁能够被动释放,
	// 同时在使用TTL后,进程需要间断renew session保活(推荐时间是ttl/2
	SessionTTL = "10s"
)

Variables

This section is empty.

Functions

func CatalogServicesList

func CatalogServicesList(address string) (map[string][]string, error)

ServicesList 获取服务列表

func GetHealthNode

func GetHealthNode(address string, service string) (nodes []string)

GetHealthNode 获取service中的健康节点

func NewHTTPError

func NewHTTPError(code int) error

NewHTTPError creates a new HTTPError instance.

Types

type AcquireReq

type AcquireReq struct {
	Acquire string `json:"acquire"`
}

AcquireReq 获取锁请求 kv update

type AgentCheck

type AgentCheck struct {
	Node        string
	CheckID     string
	Name        string
	Status      string
	Notes       string
	Output      string
	ServiceID   string
	ServiceName string
	Type        string
	Namespace   string `json:",omitempty"`
}

AgentCheck represents a check known to the agent

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func BuildWithOption

func BuildWithOption(opts ...Option) *Client

func (*Client) AcquireLock

func (c *Client) AcquireLock(name string, id string) (bool, error)

func (*Client) CatalogGetService

func (c *Client) CatalogGetService(name string) (meta.Service, error)

func (*Client) CatalogListServices

func (c *Client) CatalogListServices() ([]meta.Service, error)

func (*Client) Client

func (c *Client) Client() *consul.Client

func (*Client) CreateSession

func (c *Client) CreateSession(name string) (string, error)

func (*Client) DeleteSession

func (c *Client) DeleteSession(id string) error

func (*Client) RefreshSession

func (c *Client) RefreshSession(id string) error

func (*Client) ReleaseLock

func (c *Client) ReleaseLock(name string, id string) (bool, error)

func (*Client) ServiceDeregister

func (c *Client) ServiceDeregister(id string) error

func (*Client) ServiceRegister

func (c *Client) ServiceRegister(parm consul.AgentServiceRegistration) error

ServiceRegister 服务注册

https://developer.hashicorp.com/consul/api-docs/agent/service#register-service

type ConsulRegistReq

type ConsulRegistReq struct {
	ID      string   `json:"ID"`
	Name    string   `json:"Name"`
	Tags    []string `json:"Tags"`
	Address string   `json:"Address"`
	Port    int      `json:"Port"`
}

ConsulRegistReq regist req dat

type CreateSessionReq

type CreateSessionReq struct {
	Name string `json:"Name"`
	TTL  string `json:"TTL"`
}

CreateSessionReq new session dat

type Option

type Option func(*Parm)

func WithAddress

func WithAddress(address []string) Option

func WithAllowStale

func WithAllowStale(as bool) Option

func WithConfig

func WithConfig(cfg *consul.Config) Option

func WithQueryOption

func WithQueryOption(opt *consul.QueryOptions) Option

func WithTLS

func WithTLS(tls *tls.Config) Option

func WithTimeOut

func WithTimeOut(timeout time.Duration) Option

func WithToken

func WithToken(token string) Option

type Parm

type Parm struct {
	Addrs []string
	// contains filtered or unexported fields
}

type RenewSessionRes

type RenewSessionRes struct {
	ID          string `json:"ID"`
	Name        string `json:"Name"`
	TTL         string `json:"TTL"`
	CreateIndex string `json:"CreateIndex"`
	ModifyIndex string `json:"ModifyIndex"`
}

RenewSessionRes renew

type ServiceHealthCheck

type ServiceHealthCheck struct {
	ID          string `json:"ID"`
	Node        string `json:"Node"`
	Name        string `josn:"Name"`
	Status      string `json:"Status"` // passing
	ServiceID   string `json:"ServiceID"`
	ServiceName string `json:"ServiceName"`
}

ServiceHealthCheck 节点健康检查 check

type ServiceHealthRes

type ServiceHealthRes struct {
	Checks  []ServiceHealthCheck
	Service ServiceHealthService
}

ServiceHealthRes 节点健康检查返回

type ServiceHealthService

type ServiceHealthService struct {
	ID      string `json:"ID"`
	Service string `json:"Service"`
	Address string `json:"Address"`
}

ServiceHealthService 节点健康检查 service

Jump to

Keyboard shortcuts

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