selector

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorEmptyNameAddress = errors.New("empty name or address")

Functions

func Register

func Register(name string, s Selector)

Types

type Consul

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

func (*Consul) LoadConfig

func (c *Consul) LoadConfig(opts *Options) error

LoadConfig 加载consul配置.

func (*Consul) RegisterClient

func (c *Consul) RegisterClient(name, address string) error

RegisterClient 将client注册到服务中心.

func (*Consul) RegisterHeartbeat

func (c *Consul) RegisterHeartbeat()

RegisterHeartbeat 注册并监听心跳.

func (*Consul) RegisterService

func (c *Consul) RegisterService(name, address string) error

RegisterService 将service注册到服务中心. 此处与RegisterClient代码略微重复,但需要适应接口.

func (*Consul) Select

func (c *Consul) Select(name string) (*ServiceNodes, error)

Select 通过 Service.Name 查询具体结点.

type HeartbeatOptions

type HeartbeatOptions struct {
	Host                           string `yaml:"host"`
	Port                           string `yaml:"port"`
	Timeout                        string `yaml:"timeout"`
	Interval                       string `yaml:"interval"`
	DeregisterCriticalServiceAfter string `yaml:"deregister-critical-service-after"`
}

type Node

type Node struct {
	// Key   键: 服务名.
	Key string
	// Value 值: 结点ip地址.
	Value string
	// Blacklist 黑名单.
	Blacklist string
	// Whitelist 白名单.
	Whitelist string
	// Weight 权重.
	Weight float64
	// LastTime 最新更新时间.
	LastTime time.Duration
}

Node 服务结点.

type Options

type Options struct {
	SelectorName      string `yaml:"name"`
	Address           string `yaml:"address"`
	Scheme            string `yaml:"scheme"`
	EnableHeartbeat   bool   `yaml:"enable-heartbeat"`
	*HeartbeatOptions `yaml:"heartbeat"`
}

type Selector

type Selector interface {
	RegisterClient(name, address string) error
	RegisterService(name, address string) error
	RegisterHeartbeat()
	Select(string) (*ServiceNodes, error)
	LoadConfig(*Options) error
}

func Get

func Get(name string) Selector

type ServiceNodes

type ServiceNodes struct {
	// Name 服务名.
	Name string
	// Nodes 服务结点.
	Nodes []*Node
	// 结点数.
	Length int
	// LastTime 服务最后更新时间.
	LastTime time.Duration
	// contains filtered or unexported fields
}

ServiceNodes 单个服务.

Jump to

Keyboard shortcuts

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