validator

This commit is contained in:
withchao
2023-03-06 10:39:02 +08:00
parent 79f7e17759
commit 56306f33d7
3 changed files with 4 additions and 77 deletions
+3 -6
View File
@@ -22,7 +22,7 @@ import (
var _ context.Context // 解决goland编辑器bug
func NewMsg(zk *openKeeper.ZkClient) *Msg {
return &Msg{zk: zk}
return &Msg{zk: zk, validate: validator.New()}
}
type Msg struct {
@@ -30,7 +30,7 @@ type Msg struct {
validate *validator.Validate
}
func () SetOptions(options map[string]bool, value bool) {
func SetOptions(options map[string]bool, value bool) {
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
@@ -104,9 +104,6 @@ func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
}
return &pbData
}
func init() {
validate = validator.New()
}
func (o *Msg) client() (msg.MsgClient, error) {
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
@@ -197,7 +194,7 @@ func (o *Msg) ManagementSendMsg(c *gin.Context) {
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
apiresp.GinError(c, constant.ErrData)
return
} else if err := validate.Struct(data); err != nil {
} else if err := o.validate.Struct(data); err != nil {
apiresp.GinError(c, constant.ErrData)
return
}