You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
569 B
24 lines
569 B
1 year ago
|
package api
|
||
|
|
||
|
import (
|
||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||
|
"github.com/go-playground/validator/v10"
|
||
|
)
|
||
|
|
||
|
func RequiredIf(fl validator.FieldLevel) bool {
|
||
|
sessionType := fl.Parent().FieldByName("SessionType").Int()
|
||
|
switch sessionType {
|
||
|
case constant.SingleChatType, constant.NotificationChatType:
|
||
|
if fl.FieldName() == "RecvID" {
|
||
|
return fl.Field().String() != ""
|
||
|
}
|
||
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||
|
if fl.FieldName() == "GroupID" {
|
||
|
return fl.Field().String() != ""
|
||
|
}
|
||
|
default:
|
||
|
return true
|
||
|
}
|
||
|
return true
|
||
|
}
|