Files
open-im-server/internal/api/custom_validator.go
T

25 lines
570 B
Go
Raw Normal View History

2023-06-30 09:45:02 +08:00
package api
import (
"github.com/go-playground/validator/v10"
2023-07-03 16:29:22 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
2023-06-30 09:45:02 +08:00
)
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
}