Documentation ¶
Index ¶
- Constants
- func DecreLoad(serverId string, load int64, options ...FilterOption) error
- func GetData(key string) (string, error)
- func GetServerById(serverId string, options ...FilterOption) *treaty.Server
- func GetServerByType(serverType, serverArg string, options ...FilterOption) *treaty.Server
- func GetServerByTypeLoad(serverType string, options ...FilterOption) *treaty.Server
- func GetServerList(options ...FilterOption) map[string]*treaty.Server
- func GetServerTypeList(serverType string, options ...FilterOption) map[string]*treaty.Server
- func IncreLoad(serverId string, load int64, options ...FilterOption) error
- func InitDiscoverer(cfg config.DiscoverConf)
- func PutData(key, val string) error
- func RegDataEventHandlers(handlers ...DataEventHandler)
- func RegServerEventHandlers(handlers ...ServerEventHandler)
- func Register(server *treaty.Server) error
- func RemoveData(key string) error
- func UnRegister(server *treaty.Server) error
- type DataEventHandler
- type Discoverer
- type EtcdDiscoverer
- func (e *EtcdDiscoverer) DataEventHandlerExec(ev *clientv3.Event)
- func (e *EtcdDiscoverer) DataWatcher()
- func (e *EtcdDiscoverer) DecreLoad(serverId string, load int64, options ...FilterOption) error
- func (e *EtcdDiscoverer) DumpServers()
- func (e *EtcdDiscoverer) FindServer(serverType string) []*treaty.Server
- func (e *EtcdDiscoverer) FindServerList() map[string][]*treaty.Server
- func (e *EtcdDiscoverer) GetData(key string) (string, error)
- func (e *EtcdDiscoverer) GetServerById(serverId string, options ...FilterOption) *treaty.Server
- func (e *EtcdDiscoverer) GetServerByType(serverType, serverArg string, options ...FilterOption) *treaty.Server
- func (e *EtcdDiscoverer) GetServerByTypeLoad(serverType string, options ...FilterOption) *treaty.Server
- func (e *EtcdDiscoverer) GetServerList(options ...FilterOption) map[string]*treaty.Server
- func (e *EtcdDiscoverer) GetServerTypeList(serverType string, options ...FilterOption) map[string]*treaty.Server
- func (e *EtcdDiscoverer) IncreLoad(serverId string, load int64, options ...FilterOption) error
- func (e *EtcdDiscoverer) Init()
- func (e *EtcdDiscoverer) PutData(key, val string) error
- func (e *EtcdDiscoverer) RegDataEventHandlers(handlers ...DataEventHandler)
- func (e *EtcdDiscoverer) RegServerEventHandlers(handlers ...ServerEventHandler)
- func (e *EtcdDiscoverer) Register(server *treaty.Server) error
- func (e *EtcdDiscoverer) RegisterLoad(server *treaty.Server, load int64) error
- func (e *EtcdDiscoverer) RemoveData(key string) error
- func (e *EtcdDiscoverer) ServerEventHandlerExec(ev *clientv3.Event, server *treaty.Server)
- func (e *EtcdDiscoverer) ServerWatcher()
- func (e *EtcdDiscoverer) UnRegister(server *treaty.Server) error
- type EtcdOption
- type Filter
- type FilterOption
- type Finder
- func (f *Finder) GetServerCache(serverType string, arg any) *treaty.Server
- func (f *Finder) GetServerDiscover(serverType string, arg any, options ...FilterOption) *treaty.Server
- func (f *Finder) GetUserServer(serverType string, arg any, options ...FilterOption) *treaty.Server
- func (f *Finder) RemoveUserCache(arg any)
- func (f *Finder) ServerEventHandler(ev *clientv3.Event, server *treaty.Server)
- type Findkey
- type MaintainType
- type ServerEventHandler
- type ServerMap
- type ServerTypeItem
Constants ¶
View Source
const ( DefaultServerPrefix = "/server/" DefaultDataPrefix = "/data/" )
Variables ¶
This section is empty.
Functions ¶
func DecreLoad ¶ added in v2.5.6
func DecreLoad(serverId string, load int64, options ...FilterOption) error
func GetServerById ¶
func GetServerById(serverId string, options ...FilterOption) *treaty.Server
func GetServerByType ¶
func GetServerByType(serverType, serverArg string, options ...FilterOption) *treaty.Server
func GetServerByTypeLoad ¶ added in v2.0.3
func GetServerByTypeLoad(serverType string, options ...FilterOption) *treaty.Server
func GetServerList ¶
func GetServerList(options ...FilterOption) map[string]*treaty.Server
func GetServerTypeList ¶
func GetServerTypeList(serverType string, options ...FilterOption) map[string]*treaty.Server
func IncreLoad ¶ added in v2.5.6
func IncreLoad(serverId string, load int64, options ...FilterOption) error
func InitDiscoverer ¶
func InitDiscoverer(cfg config.DiscoverConf)
func RegDataEventHandlers ¶ added in v2.6.5
func RegDataEventHandlers(handlers ...DataEventHandler)
func RegServerEventHandlers ¶ added in v2.6.5
func RegServerEventHandlers(handlers ...ServerEventHandler)
func RemoveData ¶ added in v2.6.5
func UnRegister ¶
Types ¶
type DataEventHandler ¶ added in v2.6.5
type Discoverer ¶
type Discoverer interface { Register(server *treaty.Server) error //注册服务器 UnRegister(server *treaty.Server) error //注册服务器 GetServerList(options ...FilterOption) map[string]*treaty.Server //获取所有服务信息 GetServerById(serverId string, options ...FilterOption) *treaty.Server //根据serverId获取server信息 GetServerByType(serverType, serverArg string, options ...FilterOption) *treaty.Server //根据serverType及参数分配唯一server信息 GetServerByTypeLoad(serverType string, options ...FilterOption) *treaty.Server //根绝服务器最小负载量选择服务 GetServerTypeList(serverType string, options ...FilterOption) map[string]*treaty.Server RegServerEventHandlers(handlers ...ServerEventHandler) ServerEventHandlerExec(ev *clientv3.Event, server *treaty.Server) RegDataEventHandlers(handlers ...DataEventHandler) DataEventHandlerExec(ev *clientv3.Event) IncreLoad(serverId string, load int64, options ...FilterOption) error //负载增加 DecreLoad(serverId string, load int64, options ...FilterOption) error //负载减少 PutData(key, val string) error //增加数据 RemoveData(key string) error //删除数据 GetData(key string) (string, error) }
Discoverer find service role
type EtcdDiscoverer ¶
type EtcdDiscoverer struct { Config clientv3.Config Client *clientv3.Client ServerList map[string]*treaty.Server //serverId=>server ServerTypeMap map[string]*ServerTypeItem //serverType=>serverTypeItem ServerLock *sync.RWMutex ServerEventHandlerList []ServerEventHandler DataEventHandlerList []DataEventHandler ServerPrefix string DataPrefix string ServerChecker *regexp.Regexp DataChecker *regexp.Regexp RegLock *sync.Mutex }
EtcdDiscoverer etcd discoverer
func NewEtcdDiscoverer ¶
func NewEtcdDiscoverer(opts ...EtcdOption) *EtcdDiscoverer
NewEtcdDiscoverer init EtcdDiscoverer
func (*EtcdDiscoverer) DataEventHandlerExec ¶ added in v2.6.5
func (e *EtcdDiscoverer) DataEventHandlerExec(ev *clientv3.Event)
func (*EtcdDiscoverer) DataWatcher ¶ added in v2.6.5
func (e *EtcdDiscoverer) DataWatcher()
func (*EtcdDiscoverer) DecreLoad ¶ added in v2.5.6
func (e *EtcdDiscoverer) DecreLoad(serverId string, load int64, options ...FilterOption) error
func (*EtcdDiscoverer) DumpServers ¶
func (e *EtcdDiscoverer) DumpServers()
func (*EtcdDiscoverer) FindServer ¶
func (e *EtcdDiscoverer) FindServer(serverType string) []*treaty.Server
func (*EtcdDiscoverer) FindServerList ¶
func (e *EtcdDiscoverer) FindServerList() map[string][]*treaty.Server
func (*EtcdDiscoverer) GetData ¶ added in v2.6.5
func (e *EtcdDiscoverer) GetData(key string) (string, error)
func (*EtcdDiscoverer) GetServerById ¶
func (e *EtcdDiscoverer) GetServerById(serverId string, options ...FilterOption) *treaty.Server
func (*EtcdDiscoverer) GetServerByType ¶
func (e *EtcdDiscoverer) GetServerByType(serverType, serverArg string, options ...FilterOption) *treaty.Server
func (*EtcdDiscoverer) GetServerByTypeLoad ¶ added in v2.0.3
func (e *EtcdDiscoverer) GetServerByTypeLoad(serverType string, options ...FilterOption) *treaty.Server
func (*EtcdDiscoverer) GetServerList ¶
func (e *EtcdDiscoverer) GetServerList(options ...FilterOption) map[string]*treaty.Server
func (*EtcdDiscoverer) GetServerTypeList ¶
func (e *EtcdDiscoverer) GetServerTypeList(serverType string, options ...FilterOption) map[string]*treaty.Server
func (*EtcdDiscoverer) IncreLoad ¶ added in v2.5.6
func (e *EtcdDiscoverer) IncreLoad(serverId string, load int64, options ...FilterOption) error
func (*EtcdDiscoverer) PutData ¶ added in v2.6.5
func (e *EtcdDiscoverer) PutData(key, val string) error
func (*EtcdDiscoverer) RegDataEventHandlers ¶ added in v2.6.5
func (e *EtcdDiscoverer) RegDataEventHandlers(handlers ...DataEventHandler)
func (*EtcdDiscoverer) RegServerEventHandlers ¶ added in v2.6.5
func (e *EtcdDiscoverer) RegServerEventHandlers(handlers ...ServerEventHandler)
func (*EtcdDiscoverer) Register ¶
func (e *EtcdDiscoverer) Register(server *treaty.Server) error
Register register
func (*EtcdDiscoverer) RegisterLoad ¶ added in v2.6.3
func (e *EtcdDiscoverer) RegisterLoad(server *treaty.Server, load int64) error
Register register
func (*EtcdDiscoverer) RemoveData ¶ added in v2.6.5
func (e *EtcdDiscoverer) RemoveData(key string) error
func (*EtcdDiscoverer) ServerEventHandlerExec ¶ added in v2.6.5
func (e *EtcdDiscoverer) ServerEventHandlerExec(ev *clientv3.Event, server *treaty.Server)
func (*EtcdDiscoverer) ServerWatcher ¶ added in v2.6.5
func (e *EtcdDiscoverer) ServerWatcher()
func (*EtcdDiscoverer) UnRegister ¶
func (e *EtcdDiscoverer) UnRegister(server *treaty.Server) error
type EtcdOption ¶
type EtcdOption func(e *EtcdDiscoverer)
func WithEtcdDataPrefix ¶ added in v2.6.5
func WithEtcdDataPrefix(prefix string) EtcdOption
func WithEtcdDialTimeOut ¶
func WithEtcdDialTimeOut(d time.Duration) EtcdOption
func WithEtcdEndpoints ¶
func WithEtcdEndpoints(endpoints []string) EtcdOption
func WithEtcdServerPrefix ¶ added in v2.6.5
func WithEtcdServerPrefix(prefix string) EtcdOption
type Filter ¶ added in v2.6.5
type Filter struct {
// contains filtered or unexported fields
}
func NewFilter ¶ added in v2.6.5
func NewFilter(options ...FilterOption) *Filter
type FilterOption ¶ added in v2.6.5
type FilterOption func(f *Filter)
func FilterMaintained ¶ added in v2.6.5
func FilterMaintained(maintained MaintainType) FilterOption
func FilterVersion ¶ added in v2.6.5
func FilterVersion(version int64) FilterOption
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
func (*Finder) GetServerCache ¶
func (*Finder) GetServerDiscover ¶
func (*Finder) GetUserServer ¶
func (*Finder) RemoveUserCache ¶
type MaintainType ¶ added in v2.6.5
type MaintainType int
const ( MaintainTypeAll MaintainType = iota MaintainTypeFalse MaintainTypeTrue )
type ServerEventHandler ¶ added in v2.6.5
type ServerTypeItem ¶
type ServerTypeItem struct { List map[string]*treaty.Server // contains filtered or unexported fields }
func NewServerTypeItem ¶
func NewServerTypeItem() *ServerTypeItem
Click to show internal directories.
Click to hide internal directories.