同步代码
This commit is contained in:
44
api/heart_beat.go
Normal file
44
api/heart_beat.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"omc/omc"
|
||||
|
||||
"github.com/aceld/zinx/ziface"
|
||||
"github.com/aceld/zinx/zlog"
|
||||
"github.com/aceld/zinx/znet"
|
||||
)
|
||||
|
||||
// HeartBeatApi 心跳请求
|
||||
type HeartBeatApi struct {
|
||||
znet.BaseRouter
|
||||
}
|
||||
|
||||
func (*HeartBeatApi) Handle(request ziface.IRequest) {
|
||||
// 解包
|
||||
msgBody := omc.MsgBody{
|
||||
RawData: request.GetData(),
|
||||
Msg: make(map[string]string, 0),
|
||||
}
|
||||
if err := msgBody.Decode(); err != nil {
|
||||
zlog.Ins().ErrorF("inlaid message body %s", err.Error())
|
||||
request.GetConnection().SendMsg(omc.AckHeartBeat, omc.ErrorMsg("ackHeartBeat", "", "inlaid message body"))
|
||||
return
|
||||
}
|
||||
|
||||
reqId, ok := msgBody.Msg["reqId"]
|
||||
if !ok {
|
||||
zlog.Ins().ErrorF("missing parameter of message body")
|
||||
request.GetConnection().SendMsg(omc.AckHeartBeat, omc.ErrorMsg("ackHeartBeat", "", "missing parameter of message body"))
|
||||
return
|
||||
}
|
||||
|
||||
//ack
|
||||
ackBody := omc.MsgBody{
|
||||
MsgName: "ackHeartBeat",
|
||||
Msg: make(map[string]string, 0),
|
||||
}
|
||||
ackBody.Msg["reqId"] = reqId
|
||||
ackBody.Keys = append(ackBody.Keys, "reqId")
|
||||
ackBody.Pack()
|
||||
request.GetConnection().SendMsg(omc.AckHeartBeat, ackBody.RawData)
|
||||
}
|
||||
Reference in New Issue
Block a user