fox/etcd/inode.go

53 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package etcd
import "fmt"
const (
rootKeyServices = "services"
rootKeyTopic = "topic"
)
type INode interface {
// 注册到etcd的key
EtcdKey() string
EtcdRootKey() string
MapKey() string
}
// 服务节点信息TypeId及Type都是标记同类型的节点Name是区别该节点与其它节点的字段
type ServiceNode struct {
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"` // 版本号
}
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 {
return s.Name
}
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 {
return s.Name
}