19059e0a69
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 1s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 1s
CI / task (push) Successful in 0s
CI / user (push) Successful in 28s
CI / water (push) Successful in 1s
CI / wecom (push) Successful in 0s
314 lines
10 KiB
Go
314 lines
10 KiB
Go
package validator
|
|
|
|
import "lone-services/pkg/validate"
|
|
|
|
type GenerateQrcodeValidator struct {
|
|
ClientCode string `validate:"required,max=32"`
|
|
}
|
|
|
|
func (p GenerateQrcodeValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
}
|
|
}
|
|
|
|
type QrcodeScanValidator struct {
|
|
SessionId string `validate:"required,max=64"`
|
|
}
|
|
|
|
func (p QrcodeScanValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"SessionId.required": "session_id 不能为空",
|
|
"SessionId.max": "session_id 过长",
|
|
}
|
|
}
|
|
|
|
type QrcodeLoginValidator struct {
|
|
SessionId string `validate:"required,max=64"`
|
|
Type int32 `validate:"required,oneof=1 2"`
|
|
}
|
|
|
|
func (p QrcodeLoginValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"SessionId.required": "session_id 不能为空",
|
|
"SessionId.max": "session_id 过长",
|
|
"Type.required": "type 不能为空",
|
|
"Type.oneof": "type 传值不对",
|
|
}
|
|
}
|
|
|
|
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 UpdateValidator struct {
|
|
Name string `validate:"omitempty,max=64"`
|
|
Avatar string `validate:"omitempty,max=512"`
|
|
Gender uint32 `validate:"omitempty,oneof=0 1 2 3"`
|
|
Birthday string `validate:"omitempty,max=32"`
|
|
Mobile string `validate:"omitempty,len=11"`
|
|
RealName string `validate:"omitempty,max=64"`
|
|
}
|
|
|
|
func (p UpdateValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Name.max": "昵称过长",
|
|
"Avatar.max": "头像地址过长",
|
|
"Gender.oneof": "性别不正确",
|
|
"Birthday.max": "生日过长",
|
|
"Mobile.len": "手机号格式不正确",
|
|
"RealName.max": "真实姓名过长",
|
|
}
|
|
}
|
|
|
|
type PasswordValidator struct {
|
|
OldPassword string `validate:"required,max=64"`
|
|
Password string `validate:"required,min=6,max=64"`
|
|
}
|
|
|
|
func (p PasswordValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"OldPassword.required": "原密码不能为空",
|
|
"OldPassword.max": "原密码过长",
|
|
"Password.required": "新密码不能为空",
|
|
"Password.min": "新密码长度不能小于6位",
|
|
"Password.max": "新密码过长",
|
|
}
|
|
}
|
|
|
|
type GetOpenidValidator struct {
|
|
Code string `validate:"required,max=128"`
|
|
}
|
|
|
|
func (p GetOpenidValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Code.required": "Code 不能为空",
|
|
"Code.max": "Code 过长",
|
|
}
|
|
}
|
|
|
|
type BindMobileValidator struct {
|
|
Code string `validate:"required,max=128"`
|
|
}
|
|
|
|
func (p BindMobileValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Code.required": "code 不能为空",
|
|
"Code.max": "code 过长",
|
|
}
|
|
}
|
|
|
|
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 InternalCreateValidator 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,min=1,dive,required,max=32"`
|
|
CredentialType []string `validate:"omitempty,dive,oneof=password sms"`
|
|
Identifier string `validate:"omitempty,max=128"`
|
|
Secret string `validate:"omitempty,max=255"`
|
|
BizId int64 `validate:"omitempty,gte=0"`
|
|
}
|
|
|
|
func (p InternalCreateValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.min": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
"CredentialType.oneof": "凭证类型不正确",
|
|
}
|
|
}
|
|
|
|
type InternalGetUserInfoValidator struct {
|
|
UserId int64 `validate:"required,gt=0"`
|
|
CredentialType string `validate:"omitempty,oneof=password sms wecom openid unionid"`
|
|
SubjectType string `validate:"omitempty,oneof=sale store user"`
|
|
}
|
|
|
|
func (p InternalGetUserInfoValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"UserId.required": "用户ID不能为空",
|
|
"UserId.gt": "用户ID必须大于0",
|
|
"CredentialType.oneof": "凭证类型不正确",
|
|
"SubjectType.oneof": "主体类型不正确",
|
|
}
|
|
}
|
|
|
|
type InternalUsersByBizValidator struct {
|
|
ClientCode string `validate:"required,max=64"`
|
|
BizIds []int64 `validate:"omitempty,dive,gt=0"`
|
|
Keyword string `validate:"omitempty,max=64"`
|
|
Gender uint32 `validate:"omitempty,oneof=0 1 2 3"`
|
|
BirthdayGte string `validate:"omitempty,max=32"`
|
|
BirthdayLte string `validate:"omitempty,max=32"`
|
|
}
|
|
|
|
func (p InternalUsersByBizValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"ClientCode.required": "客户端不能为空",
|
|
"ClientCode.max": "客户端过长",
|
|
"Gender.oneof": "性别不正确",
|
|
}
|
|
}
|
|
|
|
type InternalUsersByIdsValidator struct {
|
|
Ids []int64 `validate:"required,min=1,dive,gt=0"`
|
|
}
|
|
|
|
func (p InternalUsersByIdsValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Ids.required": "用户ID不能为空",
|
|
"Ids.min": "用户ID不能为空",
|
|
}
|
|
}
|
|
|
|
type InternalUpdateMobileValidator struct {
|
|
UserId int64 `validate:"required,gt=0"`
|
|
Mobile string `validate:"required,max=20"`
|
|
}
|
|
|
|
func (p InternalUpdateMobileValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"UserId.required": "用户ID不能为空",
|
|
"UserId.gt": "用户ID必须大于0",
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
}
|
|
}
|
|
|
|
type InternalRevokeBizClientValidator struct {
|
|
UserId int64 `validate:"required,gt=0"`
|
|
ClientCode string `validate:"required,max=32"`
|
|
}
|
|
|
|
func (p InternalRevokeBizClientValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"UserId.required": "用户ID不能为空",
|
|
"UserId.gt": "用户ID必须大于0",
|
|
"ClientCode.required": "端编码不能为空",
|
|
"ClientCode.max": "端编码过长",
|
|
}
|
|
}
|
|
|
|
type InternalCheckCreateValidator struct {
|
|
Mobile string `validate:"required,max=20"`
|
|
}
|
|
|
|
func (p InternalCheckCreateValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
}
|
|
}
|
|
|
|
type InternalCheckUpdateValidator struct {
|
|
BizId int64 `validate:"required,gt=0"`
|
|
Mobile string `validate:"required,max=20"`
|
|
SubjectType string `validate:"required,oneof=sale store user"`
|
|
}
|
|
|
|
func (p InternalCheckUpdateValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"BizId.required": "业务用户ID不能为空",
|
|
"BizId.gt": "业务用户ID必须大于0",
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
"SubjectType.required": "主体类型不能为空",
|
|
"SubjectType.oneof": "主体类型不正确",
|
|
}
|
|
}
|
|
|
|
type InternalUpdateValidator 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:"omitempty,dive,required,max=32"`
|
|
CredentialType []string `validate:"omitempty"`
|
|
Identifier string `validate:"omitempty,max=128"`
|
|
Secret string `validate:"omitempty,max=255"`
|
|
BizId int64 `validate:"required,gt=0"`
|
|
SubjectType string `validate:"required,oneof=sale store user"`
|
|
}
|
|
|
|
type InternalVerifyPasswordValidator struct {
|
|
Username string `validate:"required,max=32"`
|
|
Password string `validate:"required,max=64"`
|
|
SubjectType string `validate:"omitempty,oneof=sale store user"`
|
|
ClientCode string `validate:"omitempty,max=32"`
|
|
}
|
|
|
|
func (p InternalVerifyPasswordValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Username.required": "账号不能为空",
|
|
"Username.max": "账号过长",
|
|
"Password.required": "密码不能为空",
|
|
"Password.max": "密码过长",
|
|
"SubjectType.oneof": "主体类型不正确",
|
|
"ClientCode.max": "端编码过长",
|
|
}
|
|
}
|
|
|
|
func (p InternalUpdateValidator) GetMessage() validate.ValidatorMessages {
|
|
return validate.ValidatorMessages{
|
|
"Mobile.required": "手机号不能为空",
|
|
"Mobile.max": "手机号过长",
|
|
"ClientCode.max": "端编码过长",
|
|
"CredentialType.oneof": "凭证类型不正确",
|
|
"BizId.required": "业务用户ID不能为空",
|
|
"BizId.gt": "业务用户ID必须大于0",
|
|
"SubjectType.required": "主体类型不能为空",
|
|
"SubjectType.oneof": "主体类型不正确",
|
|
}
|
|
}
|