113 lines
3.7 KiB
Go
113 lines
3.7 KiB
Go
package validator
|
|
|
|
import "lone-services/pkg/validate"
|
|
|
|
type LoginValidator struct {
|
|
ClientCode string `validate:"required,max=32"`
|
|
GrantType string `validate:"required,oneof=openid password sms"`
|
|
Code string `validate:"required_if=GrantType openid,omitempty,max=128"`
|
|
Mobile string `validate:"required_if=GrantType password,omitempty,required_if=GrantType sms,omitempty,max=20"`
|
|
Password string `validate:"required_if=GrantType password,omitempty,max=64"`
|
|
SmsCode string `validate:"required_if=GrantType sms,omitempty,max=8"`
|
|
}
|
|
|
|
func (p LoginValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
"GrantType.required": "登录方式不能为空",
|
|
"GrantType.oneof": "登录方式不正确",
|
|
"Code.required_if": "微信code不能为空",
|
|
"Mobile.required_if": "手机号不能为空",
|
|
"Password.required_if": "密码不能为空",
|
|
"SmsCode.required_if": "验证码不能为空",
|
|
}
|
|
}
|
|
|
|
type UserItemsValidator struct {
|
|
Mobile string
|
|
Page int32 `validate:"omitempty,min=1"`
|
|
Size int32 `validate:"omitempty,min=1,max=100"`
|
|
}
|
|
|
|
func (p UserItemsValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Page.min": "页码最小为1",
|
|
"Size.min": "每页数量最小为1",
|
|
"Size.max": "每页数量最大为100",
|
|
}
|
|
}
|
|
|
|
type UserStatusValidator struct {
|
|
Id int64 `validate:"required"`
|
|
Status int32 `validate:"required,oneof=1 2"`
|
|
}
|
|
|
|
func (p UserStatusValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Id.required": "用户ID不能为空",
|
|
"Status.required": "状态不能为空",
|
|
"Status.oneof": "状态传值不对",
|
|
}
|
|
}
|
|
|
|
type EnsureBizIdentityValidator struct {
|
|
Mobile string `validate:"required,max=20"`
|
|
Name string `validate:"omitempty,max=64"`
|
|
Avatar string `validate:"omitempty,max=255"`
|
|
Gender uint32 `validate:"omitempty,oneof=0 1 2 3"`
|
|
Birthday string `validate:"omitempty,max=12"`
|
|
ClientCode string `validate:"required,max=32"`
|
|
CredentialType string `validate:"omitempty,max=32"`
|
|
Identifier string `validate:"omitempty,max=128"`
|
|
Secret string `validate:"omitempty,max=255"`
|
|
}
|
|
|
|
func (p EnsureBizIdentityValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
}
|
|
}
|
|
|
|
type UsersByIdsValidator struct {
|
|
Ids []int64 `validate:"required,min=1,dive,gt=0"`
|
|
}
|
|
|
|
func (p UsersByIdsValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Ids.required": "用户ID不能为空",
|
|
"Ids.min": "用户ID不能为空",
|
|
}
|
|
}
|
|
|
|
type UpdateMobileValidator struct {
|
|
UserId int64 `validate:"required,gt=0"`
|
|
Mobile string `validate:"required,max=20"`
|
|
}
|
|
|
|
func (p UpdateMobileValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"UserId.required": "用户ID不能为空",
|
|
"UserId.gt": "用户ID必须大于0",
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
}
|
|
}
|
|
|
|
type RevokeBizClientValidator struct {
|
|
UserId int64 `validate:"required,gt=0"`
|
|
ClientCode string `validate:"required,max=32"`
|
|
}
|
|
|
|
func (p RevokeBizClientValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"UserId.required": "用户ID不能为空",
|
|
"UserId.gt": "用户ID必须大于0",
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
}
|
|
}
|