kra/pkg/utils/verify.go

79 lines
2.3 KiB
Go

package utils
// 预定义验证规则
var (
IdVerify = Rules{"ID": []string{NotEmpty()}}
ApiVerify = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
MenuVerify = Rules{"Path": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
MenuMetaVerify = Rules{"Title": {NotEmpty()}}
LoginVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}}
RegisterVerify = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
PageInfoVerify = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
CustomerVerify = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
AutoCodeVerify = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}}
AutoPackageVerify = Rules{"PackageName": {NotEmpty()}}
AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}}
AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}}
OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}}
ChangePasswordVerify = Rules{"Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
SetUserAuthorityVerify = Rules{"AuthorityId": {NotEmpty()}}
)
// Rules 验证规则类型
type Rules map[string][]string
// NotEmpty 非空验证
func NotEmpty() string {
return "notEmpty"
}
// Ge 大于等于验证
func Ge(value string) string {
return "ge=" + value
}
// Le 小于等于验证
func Le(value string) string {
return "le=" + value
}
// Gt 大于验证
func Gt(value string) string {
return "gt=" + value
}
// Lt 小于验证
func Lt(value string) string {
return "lt=" + value
}
// Eq 等于验证
func Eq(value string) string {
return "eq=" + value
}
// Ne 不等于验证
func Ne(value string) string {
return "ne=" + value
}
// Len 长度验证
func Len(value string) string {
return "len=" + value
}
// MinLen 最小长度验证
func MinLen(value string) string {
return "minLen=" + value
}
// MaxLen 最大长度验证
func MaxLen(value string) string {
return "maxLen=" + value
}
// Regexp 正则验证
func Regexp(value string) string {
return "regexp=" + value
}