同步代码
This commit is contained in:
48
core/utils.go
Normal file
48
core/utils.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/aceld/zinx/ziface"
|
||||
"omc/omc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NeBind struct {
|
||||
NeType string
|
||||
NeId string
|
||||
}
|
||||
|
||||
func ConvertBindFlag(bindFlag string) (NeBind, error) {
|
||||
var neBind NeBind
|
||||
nb := strings.Split(bindFlag, "#")
|
||||
if len(nb) != 2 {
|
||||
return neBind, errors.New("ne bind flag invalid")
|
||||
}
|
||||
neBind.NeType = nb[0]
|
||||
neBind.NeId = nb[1]
|
||||
return neBind, nil
|
||||
}
|
||||
|
||||
// APIDecode 消息解析
|
||||
func APIDecode(request ziface.IRequest, checker []string) (*omc.MsgBody, error) {
|
||||
// 消息处理
|
||||
msgBody := omc.MsgBody{
|
||||
RawData: request.GetData(),
|
||||
Msg: make(map[string]string, 0),
|
||||
}
|
||||
if err := msgBody.Decode(); err != nil {
|
||||
return nil, errors.New("inlaid message body")
|
||||
}
|
||||
for _, v := range checker {
|
||||
if _, ok := msgBody.Msg[v]; !ok {
|
||||
return nil, errors.New("missing parameter of message body")
|
||||
}
|
||||
}
|
||||
uID, err := request.GetConnection().GetProperty("UID")
|
||||
if err != nil {
|
||||
request.GetConnection().Stop()
|
||||
return nil, errors.New("server internal error")
|
||||
}
|
||||
msgBody.UID = uID.(string)
|
||||
return &msgBody, nil
|
||||
}
|
||||
Reference in New Issue
Block a user