refactor(common): 使用 sync.Map 优化全局客户端映射 将 common/cool/global.go 中的 Clientmap 从普通 map 替换为 sync.Map, 以提高并发安全性。同时迁移相关操作函数至 cool 包中统一管理。 更新了 rpc 和 service 层代码,确保正确调用新的客户端管理方法。 在 InfoService 中新增 Kick 方法用于处理用户踢出逻辑。 ```
39 lines
753 B
Go
39 lines
753 B
Go
package admin
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/blazing/service"
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
type PlayerController struct {
|
|
*cool.Controller
|
|
}
|
|
|
|
func init() {
|
|
var task_info_controller = &PlayerController{
|
|
&cool.Controller{
|
|
Prefix: "/admin/sun/player",
|
|
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
|
Service: service.NewInfoService(0),
|
|
},
|
|
}
|
|
// 注册路由
|
|
cool.RegisterController(task_info_controller)
|
|
}
|
|
|
|
type KickReq struct {
|
|
g.Meta `path:"/kick" method:"POST"`
|
|
ID uint32 `json:"id"`
|
|
}
|
|
|
|
func (c *PlayerController) Kick(ctx context.Context, req *KickReq) (res *cool.BaseRes, err error) {
|
|
res = &cool.BaseRes{}
|
|
service.NewUserService(0).Info.Kick(uint32(req.ID))
|
|
|
|
return
|
|
|
|
}
|