网络开发整体框架
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
916 B

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),
)
}