fox/etcd/inode.go

77 lines
2.1 KiB
Go
Raw Normal View History

2025-05-25 20:02:15 +08:00
package etcd
import "fmt"
const (
rootKeyServices = "services"
rootKeyTopic = "topic"
)
type INode interface {
// 注册到etcd的key
EtcdKey() string
EtcdRootKey() string
MapKey() string
}
2025-06-16 22:30:58 +08:00
type ServiceNodeStateType int
const (
2025-06-17 00:00:57 +08:00
SNST_Unknown = 0 // 无状态服务,如大厅,聊天服,匹配服,登陆服等
SNST_Stateless = 1 // 无状态服务,如大厅,聊天服,匹配服,登陆服等
SNST_Stateful = 2 // 有状态服务,主要是各类玩法服,需要记录玩家在哪个玩法服里面,以便消息不会发到同玩法的其它节点服上
SNST_Ordered = 3 // 有序服务主要是db服这类需要根据玩家id hash到固定的节点上保证数据一致性
2025-06-16 22:30:58 +08:00
)
func (s ServiceNodeStateType) String() string {
switch s {
case SNST_Stateless:
return "stateless"
case SNST_Stateful:
return "stateful"
case SNST_Ordered:
return "ordered"
2025-06-17 00:00:57 +08:00
case SNST_Unknown:
2025-06-16 22:30:58 +08:00
return "unknown"
2025-06-17 00:00:57 +08:00
default:
return fmt.Sprint(s)
2025-06-16 22:30:58 +08:00
}
}
2025-05-26 16:02:54 +08:00
// 服务节点信息TypeId及Type都是标记同类型的节点Name是区别该节点与其它节点的字段
2025-05-25 20:02:15 +08:00
type ServiceNode struct {
2025-06-21 11:36:31 +08:00
TypeId int `json:"type_id"` // 服务类型id与Type字段功能一样 由proto定义gate通过该字段找到这类服务的所有节点信息
Name string `json:"name"` // 服务名 多个同类服务依赖name区分:lobby1,lobby2,lobby3等等
Type string `json:"type"` // 服务类型:lobby, game, gate等等
Version string `json:"version"` // 版本号
2025-05-25 20:02:15 +08:00
}
func (s ServiceNode) EtcdKey() string {
return fmt.Sprintf("/%s/%s/%s", rootKeyServices, s.Type, s.Name)
}
func (s ServiceNode) EtcdRootKey() string {
return rootKeyServices
}
func (s ServiceNode) MapKey() string {
2025-05-26 16:02:54 +08:00
return s.Name
2025-05-25 20:02:15 +08:00
}
type TopicNode struct {
Name string `json:"name"` // topic名
Creator string `json:"creator"` // topic创建者
}
func (s TopicNode) EtcdKey() string {
return fmt.Sprintf("/%s/%s/%s", rootKeyTopic, s.Creator, s.Name)
}
func (s TopicNode) EtcdRootKey() string {
return rootKeyTopic
}
func (s TopicNode) MapKey() string {
2025-05-26 16:02:54 +08:00
return s.Name
2025-05-25 20:02:15 +08:00
}