package cool // 存值示例 func AddClient(id uint32, client *ClientHandler) { // 普通map:Clientmap[id] = client Clientmap.Store(id, client) // sync.Map存值 } // 取值示例 func GetClient(id uint32) (*ClientHandler, bool) { // 普通map:client, ok := Clientmap[id] val, ok := Clientmap.Load(id) // sync.Map取值 if !ok { return nil, false } // 类型断言(确保value是*ClientHandler) client, ok := val.(*ClientHandler) return client, ok } type ClientHandler struct { KickPerson func(uint32) error //踢人,这里是返回具体的logic QuitSelf func(int) error //关闭服务器进程 Broadcast func(string) int //全服广播,返回的是在线人数 }