Documentation ¶
Index ¶
- Variables
- func GetPath(groupid uint32, stype uint32, sid uint64) string
- func GetPathLoad(groupid uint32, stype uint32, sid uint64) string
- func GetPathServerInfo(pathname string) (groupid uint32, stype uint32, sid uint64)
- func GetWatchByType(sType global.ServerTypeEnum) string
- func GetWatchPath(sGroup uint32, sType uint32) string
- type DiscoveryMgr
- func (mgr *DiscoveryMgr) ClearServerInfoAll()
- func (mgr *DiscoveryMgr) GetServerById(groupid uint32, stype global.ServerTypeEnum, serverId uint64) (IServerInfo, error)
- func (mgr *DiscoveryMgr) GetServerByType(sGroup uint32, sType global.ServerTypeEnum) (result IServerInfo, err error)
- func (mgr *DiscoveryMgr) GetServerList(sType global.ServerTypeEnum, sGroup uint32) ([]IServerInfo, error)
- func (mgr *DiscoveryMgr) GetServerListByType(sType global.ServerTypeEnum) ([]IServerInfo, error)
- func (mgr *DiscoveryMgr) Start() (err error)
- func (mgr *DiscoveryMgr) UpLoad()
- func (mgr *DiscoveryMgr) Watch(stype, groupid uint32, smap IServerMap)
- func (mgr *DiscoveryMgr) WatchByStype(stype global.ServerTypeEnum, smap IServerMap)
- type IExt
- type IServerInfo
- type IServerMap
- type ServerInfo
- func (this *ServerInfo) Copy() IServerInfo
- func (this *ServerInfo) GetGroupID() uint32
- func (this *ServerInfo) GetListenAdd(v string) string
- func (this *ServerInfo) GetLoad() int32
- func (this *ServerInfo) GetOthGroupID() uint32
- func (this *ServerInfo) GetServerID() uint64
- func (this *ServerInfo) GetSrvType() uint32
- func (this *ServerInfo) GetToken() string
- func (this *ServerInfo) SetLoad(v int32)
- type ServerMapByGway
- func (this *ServerMapByGway) Delete(path string)
- func (this *ServerMapByGway) DeleteAll()
- func (this *ServerMapByGway) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
- func (this *ServerMapByGway) GetListByType(styp uint32) (result []IServerInfo, err error)
- func (this *ServerMapByGway) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)
- func (this *ServerMapByGway) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)
- func (this *ServerMapByGway) Put(sinfo IServerInfo)
- func (this *ServerMapByGway) UpLoad(path string, val int32) IServerInfo
- type ServerMapByMinID
- type ServerMapByRand
- func (this *ServerMapByRand) Delete(path string)
- func (this *ServerMapByRand) DeleteAll()
- func (this *ServerMapByRand) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
- func (this *ServerMapByRand) GetListByType(styp uint32) (result []IServerInfo, err error)
- func (this *ServerMapByRand) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)
- func (this *ServerMapByRand) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)
- func (this *ServerMapByRand) Put(sinfo IServerInfo)
- func (this *ServerMapByRand) UpLoad(path string, val int32) IServerInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrServerBusy = errors.New("Get server failed, busy")
ErrServerBusy 服务器忙
Functions ¶
func GetPathServerInfo ¶
折路径
Types ¶
type DiscoveryMgr ¶
type DiscoveryMgr struct {
// contains filtered or unexported fields
}
使用ETCD进行服务发现
func NewDiscoveryMgr ¶
func NewDiscoveryMgr(thgo *threads.ThreadGo, ext IExt) *DiscoveryMgr
func (*DiscoveryMgr) ClearServerInfoAll ¶
func (mgr *DiscoveryMgr) ClearServerInfoAll()
清空服务器信息,因为可能是脏数据
func (*DiscoveryMgr) GetServerById ¶
func (mgr *DiscoveryMgr) GetServerById(groupid uint32, stype global.ServerTypeEnum, serverId uint64) (IServerInfo, error)
GetServerById 根据服务器类型和ID取服务器
func (*DiscoveryMgr) GetServerByType ¶
func (mgr *DiscoveryMgr) GetServerByType(sGroup uint32, sType global.ServerTypeEnum) (result IServerInfo, err error)
根据负载逻辑,获取服务器
func (*DiscoveryMgr) GetServerList ¶
func (mgr *DiscoveryMgr) GetServerList(sType global.ServerTypeEnum, sGroup uint32) ([]IServerInfo, error)
根据负载逻辑,获取服务器
func (*DiscoveryMgr) GetServerListByType ¶
func (mgr *DiscoveryMgr) GetServerListByType(sType global.ServerTypeEnum) ([]IServerInfo, error)
获取指定服务器类型的所有group服务器列表
func (*DiscoveryMgr) Watch ¶
func (mgr *DiscoveryMgr) Watch(stype, groupid uint32, smap IServerMap)
监听指定服务器类型下的指定分组
func (*DiscoveryMgr) WatchByStype ¶
func (mgr *DiscoveryMgr) WatchByStype(stype global.ServerTypeEnum, smap IServerMap)
监听所有group下的指定服务器类型
type IExt ¶
type IExt interface { //根据类型生成一个新的IServerInfo对象,用与从etcd读出来后进行填充 NewInfo(stype global.ServerTypeEnum) IServerInfo // 获取自己服务器需要注册的信息 GetSelfInfo() IServerInfo //获取到新的服务器信息的时候回调,一般用来判断是否需要连接这个服务器 WatchInfoCallBack(sinfo IServerInfo) //获取ETCD的实例 GetEtcd() *etcd.EtcdAccess }
外部对象需要实现的逻辑
type IServerInfo ¶
type IServerInfo interface { //服务器组ID GetGroupID() uint32 //服务器ID GetServerID() uint64 //服务器类型 GetSrvType() uint32 //服务器公共组ID GetOthGroupID() uint32 //Token GetToken() string //获取指定类型的连接地址 GetListenAdd(v string) string // 服务器繁忙数值 0到100,100表示很忙 GetLoad() int32 // 设置服务器繁忙数值 SetLoad(v int32) //服务一个副本出来 Copy() IServerInfo }
服务器信息
type IServerMap ¶
type IServerMap interface { //加入服务器信息 Put(sinfo IServerInfo) //删除一个服务器信息 Delete(path string) //更新Load值 UpLoad(path string, val int32) IServerInfo //根据负载逻辑,获取服务器 GetBalancing(sType, sGroup uint32) (result IServerInfo, err error) //获取指定类型服务器列表 GetListByType(sType uint32) ([]IServerInfo, error) //获取组的指定类型服务器列表 GetListByTypeAGroup(sType, sGroup uint32) ([]IServerInfo, error) //获取指定服务器 GetServerByID(sType, sGroup uint32, serverId uint64) (result IServerInfo, err error) //删除所有服务器信息 DeleteAll() }
type ServerInfo ¶
type ServerInfo struct { ServerID uint64 //服务器ID SrvType global.ServerTypeEnum //服务器类型 GroupID uint32 //服务器组ID OthGroupID uint32 //对应公共组ID ListenMap map[string]*global.ListenCfg //地址信息 Token string //链接过去用来验证的Token Load int32 //服务器繁忙数值 0到100,100表示很忙 }
注册在etcd中的服务器信息,上层可以组合它实现IServerInfo,实现自定义注册数据
type ServerMapByGway ¶
type ServerMapByGway struct { Lock *sync.RWMutex //服务器信息 Srvli map[uint64]map[uint64]IServerInfo Allli []IServerInfo }
Login上的Gateway的负载器
func NewServerMapByGway ¶
func NewServerMapByGway() (result *ServerMapByGway)
func (*ServerMapByGway) GetBalancing ¶
func (this *ServerMapByGway) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
根据负载逻辑,获取服务器
func (*ServerMapByGway) GetListByType ¶
func (this *ServerMapByGway) GetListByType(styp uint32) (result []IServerInfo, err error)
获取指定类型服务器列表
func (*ServerMapByGway) GetListByTypeAGroup ¶
func (this *ServerMapByGway) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)
获取组的指定类型服务器列表
func (*ServerMapByGway) GetServerByID ¶
func (this *ServerMapByGway) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)
获取指定服务器
func (*ServerMapByGway) UpLoad ¶
func (this *ServerMapByGway) UpLoad(path string, val int32) IServerInfo
更新Load值
type ServerMapByMinID ¶
type ServerMapByMinID struct {
ServerMapByRand
}
优先分配小服务ID
func NewServerMapByMinID ¶
func NewServerMapByMinID() (result *ServerMapByMinID)
func (*ServerMapByMinID) GetBalancing ¶
func (this *ServerMapByMinID) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
根据负载逻辑,获取服务器
type ServerMapByRand ¶
type ServerMapByRand struct { Lock *sync.RWMutex //服务器信息 Srvli map[uint64]map[uint64]IServerInfo }
随机负载
func NewServerMapByRand ¶
func NewServerMapByRand() (result *ServerMapByRand)
func (*ServerMapByRand) GetBalancing ¶
func (this *ServerMapByRand) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
根据负载逻辑,获取服务器
func (*ServerMapByRand) GetListByType ¶
func (this *ServerMapByRand) GetListByType(styp uint32) (result []IServerInfo, err error)
获取指定类型服务器列表
func (*ServerMapByRand) GetListByTypeAGroup ¶
func (this *ServerMapByRand) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)
获取组的指定类型服务器列表
func (*ServerMapByRand) GetServerByID ¶
func (this *ServerMapByRand) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)
获取指定服务器
func (*ServerMapByRand) UpLoad ¶
func (this *ServerMapByRand) UpLoad(path string, val int32) IServerInfo
更新Load值
Click to show internal directories.
Click to hide internal directories.