3 Star 13 Fork 7

NightTC/Gobige

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
IServerInfo.go 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
buguang 提交于 2025-03-24 17:40 +08:00 . feat(server): 增加服务器状态管理功能
package serverMgr
import (
"sync/atomic"
"gitee.com/night-tc/gobige/global"
"gitee.com/night-tc/gobige/msgdef/protomsg"
)
/*
服务器信息
*/
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() int64
// 设置服务器繁忙数值
SetLoad(v int64)
// 服务器状态
GetStatus() protomsg.ServerStatus
// 设置服务器状态
SetStatus(v int32)
}
// 注册在etcd中的服务器信息,上层可以组合它实现IServerInfo,实现自定义注册数据
type ServerInfo struct {
Number uint64 //线编号
ServerID uint64 //服务器ID
SrvType global.ServerTypeEnum //服务器类型
GroupID uint32 //服务器组ID
OthGroupID uint32 //对应公共组ID
ListenMap map[string]string //地址信息
Token string //链接过去用来验证的Token
Load int64 //服务器繁忙数值 0到100,100表示很忙
Status int32 // protomsg.ServerStatus
}
// 服务器组ID
func (this *ServerInfo) GetGroupID() uint32 {
return this.GroupID
}
// 服务器ID
func (this *ServerInfo) GetServerID() uint64 {
return this.ServerID
}
// 服务器类型
func (this *ServerInfo) GetSrvType() uint32 {
return this.SrvType
}
// 服务器公共组ID
func (this *ServerInfo) GetOthGroupID() uint32 {
return this.OthGroupID
}
// Token
func (this *ServerInfo) GetToken() string {
return this.Token
}
// 获取指定类型的连接地址
func (this *ServerInfo) GetListenAdd(v string) string {
return this.ListenMap[v]
}
// 服务器繁忙数值 0到100,100表示很忙
func (this *ServerInfo) GetLoad() int64 {
return atomic.LoadInt64(&this.Load)
}
// 设置服务器繁忙数值
func (this *ServerInfo) SetLoad(v int64) {
atomic.StoreInt64(&this.Load, v)
}
func (this *ServerInfo) GetStatus() protomsg.ServerStatus {
return protomsg.ServerStatus(this.Status)
}
func (this *ServerInfo) SetStatus(v int32) {
atomic.StoreInt32(&this.Status, v)
}
// // 服务一个副本出来
// func (this *ServerInfo) Copy() IServerInfo {
// result := ServerInfo{}
// result = *this
// return &result
// }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/night-tc/gobige.git
git@gitee.com:night-tc/gobige.git
night-tc
gobige
Gobige
344351ffdef8

搜索帮助