discover

package
v0.0.0-...-575011b Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TTLSec                = 15 * time.Second
	TTLInt                = 15
	RevoteSec             = 10 * time.Second
	TokenLength           = 16
	EtcdClientDialTimeout = 5 * time.Second
)
View Source
const (
	UpdateSvrDefIntervalSec = 5 // Sec
)

Variables

View Source
var (
	DefaultEtcdCfg = clientv3.Config{
		DialTimeout: EtcdClientDialTimeout,
	}
)

Functions

This section is empty.

Types

type Discover

type Discover interface {
	Init() (err error)

	// 获取这个服务的随机一个addr
	GetRandomAddr(servername string) (addr string, err error)

	// 获取这个服务的所有服务地址
	GetAllAddrs(servername string) (addrs []string, err error)
}

func NewDiscoverWithEtcdCfg

func NewDiscoverWithEtcdCfg(env string, cfg clientv3.Config) (d Discover, err error)

type DiscoverImpl

type DiscoverImpl struct {
	Cfg clientv3.Config

	Str2SvrDef map[string]*SvrDef

	// 初始化的时候必须要设置
	Env string
	// contains filtered or unexported fields
}

func (*DiscoverImpl) GetAllAddrs

func (di *DiscoverImpl) GetAllAddrs(servername string) (addrs []string, err error)

func (*DiscoverImpl) GetRandomAddr

func (di *DiscoverImpl) GetRandomAddr(servername string) (addr string, err error)

func (*DiscoverImpl) Init

func (di *DiscoverImpl) Init() (err error)

type Register

type Register interface {
	Init(servername, addr, env string, cfg clientv3.Config) error
	Serve()
}

func NewRegisterWithEtcdCfg

func NewRegisterWithEtcdCfg(servername, addr, env string, cfg clientv3.Config) (r Register, err error)

type RegisterImpl

type RegisterImpl struct {
	ServerName string
	Env        string
	Addr       string
	Token      string
	Cfg        clientv3.Config
	// contains filtered or unexported fields
}

func (*RegisterImpl) Init

func (ri *RegisterImpl) Init(servername, addr, env string, cfg clientv3.Config) (err error)

func (*RegisterImpl) Serve

func (ri *RegisterImpl) Serve()

type SvrDef

type SvrDef struct {
	ServerName string
	AddrsMap   map[string]string
	AddrsMapMu sync.RWMutex
	GrpcCliMap map[string]*grpc.ClientConn
}

func NewSvrDef

func NewSvrDef(servername string, kvs *[]*mvccpb.KeyValue) *SvrDef

func (*SvrDef) AddrsList

func (sd *SvrDef) AddrsList() (addrs []string)

func (*SvrDef) RandomAddr

func (sd *SvrDef) RandomAddr() (addr string)

func (*SvrDef) Update

func (sd *SvrDef) Update(kvs *[]*mvccpb.KeyValue)

Jump to

Keyboard shortcuts

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