refactor(logic): 重构逻辑处理和错误处理机制
- 新增 Conn 结构体的 NewConn 工厂方法 - 优化 Controller 中的 Recv 方法,增加错误处理逻辑 - 修改 GetServer、Login、MapHot 等方法的返回值类型 - 重构 SystemTimeInfo 方法,使用新的 OutInfo 接口 - 更新 CommendSvrInfo 结构体和相关方法 - 统一错误处理机制,使用新的 OutInfo 接口
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@@ -96,10 +97,6 @@ func init() { //默认初始化扫描
|
||||
glog.Warning(context.Background(), "方法参数必须是结构体", method.Name, "跳过注册")
|
||||
continue
|
||||
}
|
||||
// if !cmd.Isexist(cmd.CommandID, cmd.EnumCommandID(func_cmd)) {
|
||||
// fmt.Println("ID方法存在cmd未注册", func_cmd)
|
||||
|
||||
// }
|
||||
|
||||
if cool.Config.PortBL == 0 && func_cmd > 1000 { //判断login服务器
|
||||
break
|
||||
@@ -144,13 +141,10 @@ func getcmd(t reflect.Type) uint32 {
|
||||
return gconv.Uint32(field.Tag.Get("cmd"))
|
||||
|
||||
}
|
||||
// fmt.Printf(" 类型: %v\n", field.Type)
|
||||
// fmt.Printf(" 标签: %q\n", field.Tag)
|
||||
|
||||
// 递归处理嵌套结构体
|
||||
if field.Type.Kind() == reflect.Struct ||
|
||||
(field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct) {
|
||||
fmt.Println(" 嵌套结构体字段:")
|
||||
|
||||
nestedType := field.Type
|
||||
if nestedType.Kind() == reflect.Ptr {
|
||||
nestedType = nestedType.Elem()
|
||||
@@ -207,19 +201,26 @@ func Recv(c gnet.Conn, data handler.TomeeHeader) {
|
||||
params = append(params, ptrValue1, reflect.ValueOf(c))
|
||||
}
|
||||
|
||||
ret :=cmdlister.Call(params)
|
||||
ret := cmdlister.Call(params)
|
||||
|
||||
r := entity.Conn{MainConn: c}
|
||||
r := entity.NewConn(c) //这里实现新增客户端
|
||||
|
||||
if len(ret)<=0 {
|
||||
if len(ret) <= 0 { //如果判断没有参数,那就说明这个包没有返回参数
|
||||
return
|
||||
}
|
||||
a,ok:=ret[0].Interface().([]byte)
|
||||
if ok {
|
||||
r.SendPack(a)
|
||||
|
||||
aa, ok := ret[1].Interface().(service.OutInfo) //判断错误
|
||||
|
||||
if ok && aa != nil { //这里实现回复错误包
|
||||
|
||||
g.Log().Error(context.Background(), aa.Error(), aa.Code())
|
||||
|
||||
data.Result = uint32(aa.Code())
|
||||
r.SendPack(data.Pack(nil))
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
r.SendPack(data.Pack(ret[0].Interface()))
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user