mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 11:40:01 +08:00
validate modify
This commit is contained in:
parent
8ac9090171
commit
8777dd35df
@ -9,16 +9,17 @@ package gate
|
|||||||
import (
|
import (
|
||||||
"Open_IM/src/common/constant"
|
"Open_IM/src/common/constant"
|
||||||
"Open_IM/src/common/log"
|
"Open_IM/src/common/log"
|
||||||
"github.com/mitchellh/mapstructure"
|
"bytes"
|
||||||
|
"encoding/gob"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Req struct {
|
type Req struct {
|
||||||
ReqIdentifier int32 `json:"reqIdentifier" validate:"required"`
|
ReqIdentifier int32 `json:"reqIdentifier" validate:"required"`
|
||||||
Token string `json:"token" validate:"required"`
|
Token string `json:"token" validate:"required"`
|
||||||
SendID string `json:"sendID" validate:"required"`
|
SendID string `json:"sendID" validate:"required"`
|
||||||
OperationID string `json:"operationID" validate:"required"`
|
OperationID string `json:"operationID" validate:"required"`
|
||||||
MsgIncr string `json:"msgIncr" validate:"required"`
|
MsgIncr string `json:"msgIncr" validate:"required"`
|
||||||
Data interface{} `json:"data"`
|
Data []byte `json:"data"`
|
||||||
}
|
}
|
||||||
type Resp struct {
|
type Resp struct {
|
||||||
ReqIdentifier int32 `json:"reqIdentifier"`
|
ReqIdentifier int32 `json:"reqIdentifier"`
|
||||||
@ -60,10 +61,18 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
|||||||
data = SeqListData{}
|
data = SeqListData{}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if err := mapstructure.WeakDecode(m.Data, &data); err != nil {
|
b := bytes.NewBuffer(m.Data)
|
||||||
log.ErrorByKv("map to Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
dec := gob.NewDecoder(b)
|
||||||
|
err := dec.Decode(&data)
|
||||||
|
if err != nil {
|
||||||
|
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||||
return false, 203, err.Error(), nil
|
return false, 203, err.Error(), nil
|
||||||
} else if err := validate.Struct(data); err != nil {
|
}
|
||||||
|
//if err := mapstructure.WeakDecode(m.Data, &data); err != nil {
|
||||||
|
// log.ErrorByKv("map to Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||||
|
// return false, 203, err.Error(), nil
|
||||||
|
//} else
|
||||||
|
if err = validate.Struct(data); err != nil {
|
||||||
log.ErrorByKv("data args validate err", "", "err", err.Error(), "reqIdentifier", r)
|
log.ErrorByKv("data args validate err", "", "err", err.Error(), "reqIdentifier", r)
|
||||||
return false, 204, err.Error(), nil
|
return false, 204, err.Error(), nil
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user