hpds_net_framework/msg.go

45 lines
916 B
Go
Raw Normal View History

2022-08-03 16:55:40 +08:00
package hpds_net_framework
import (
"git.hpds.cc/Component/logging"
"go.uber.org/zap"
"reflect"
"runtime/debug"
"time"
)
// 回调传参常量
const (
Msg = iota
Conn
Raw
)
// 消息信息
type msgInfo struct {
msgId int
msgType reflect.Type
msgCallback func(args ...interface{})
}
// 执行消息回调
func execute(mInfo msgInfo, msg interface{}, writer interface{}, body []byte, id uint32) {
defer func() {
if r := recover(); r != nil {
logging.L().Error("panic at msg",
zap.Uint32("id", id),
zap.Any("recover", r),
zap.ByteString("stack", debug.Stack()),
)
}
}()
begin := time.Now().UnixNano() / int64(time.Millisecond)
mInfo.msgCallback(msg, writer, body)
costs := time.Now().UnixNano()/int64(time.Millisecond) - begin
logging.L().Debug("execute logic",
zap.Int("msgId", mInfo.msgId),
zap.Int64("costs", costs),
zap.Any("msgType", mInfo.msgType),
)
}