fix bug: invited/kick failed due to json tag validation

pull/351/head
skiffer-git 2 years ago
parent 1b31de18e4
commit 6759e0c25b

@ -65,7 +65,6 @@ func main() {
defaultPorts := config.Config.Demo.Port
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10004 as port")
flag.Parse()
fmt.Println("start demo api server, port: ", *ginPort)
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
if config.Config.Api.ListenIP != "" {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)

@ -42,10 +42,14 @@ func KickGroupMember(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
if len(params.KickedUserIDList) > constant.MaxNotificationNum {
errMsg := params.OperationID + " too many members " + utils.Int32ToString(int32(len(params.KickedUserIDList)))
log.Error(params.OperationID, errMsg)
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errMsg})
return
}
req := &rpc.KickGroupMemberReq{}
utils.CopyStructFields(req, &params)
var ok bool
var errInfo string
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
@ -318,6 +322,12 @@ func InviteUserToGroup(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
if len(params.InvitedUserIDList) > constant.MaxNotificationNum {
errMsg := params.OperationID + " too many members " + utils.Int32ToString(int32(len(params.InvitedUserIDList)))
log.Error(params.OperationID, errMsg)
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": errMsg})
return
}
req := &rpc.InviteUserToGroupReq{}
utils.CopyStructFields(req, &params)

@ -16,7 +16,7 @@ type CommDataResp struct {
type KickGroupMemberReq struct {
GroupID string `json:"groupID" binding:"required"`
KickedUserIDList []string `json:"kickedUserIDList" binding:"required, min=1, max=100"`
KickedUserIDList []string `json:"kickedUserIDList" binding:"required"`
Reason string `json:"reason"`
OperationID string `json:"operationID" binding:"required"`
}
@ -38,7 +38,7 @@ type GetGroupMembersInfoResp struct {
type InviteUserToGroupReq struct {
GroupID string `json:"groupID" binding:"required"`
InvitedUserIDList []string `json:"invitedUserIDList" binding:"required, min=1, max=100"`
InvitedUserIDList []string `json:"invitedUserIDList" binding:"required"`
Reason string `json:"reason"`
OperationID string `json:"operationID" binding:"required"`
}

Loading…
Cancel
Save