-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
example improvement suggestion #7
Comments
suggest add some examples of Gin with tagexpr |
No problem! |
type Request struct {
Method string `json:"method" vd:"($=='GET' || $=='POST' || $=='PUT' || $=='DELETE' );msg:sprintf('invalid Method: %v',$)"`
Url string `json:"url" vd:"regexp('^http[s]?://.+');msg:sprintf('url无效地址: %v',$)"`
} type FieldInfo struct {
Name string `json:"name" vd:"regexp('^\\w+$');msg:'格式错误'"`
Type string `json:"field_type" vd:"($=='string'||$=='object'||$=='int'||$=='float'||$=='array');msg:sprintf('%s类型有误%s',(Name)$,$)"`
Label string `json:"label" vd:"len($)>0;msg:sprintf('%s的字段名称未填写',(Name)$)"`
Descript string `json:"descript" vd:"len($)>0;msg:sprintf('%s的字段说明未填写',(Name)$)"`
} type StructName struct {
Name string `json:"name" xorm:"name" vd:"@:len($)>0 && len($)<=15;msg:'请输入xxxx名称,不超过15个字'"`
FieldName1 int64 `json:"organization" xorm:"organization" vd:"$>0;msg:'请选择xxxx'"`
FieldName2 string `json:"descript" xorm:"descript" vd:"@:len($)>0 && len($)<=200;msg:'请输入xxxx描述,不超过200个字'"`
FieldName3 string `json:"cover" xorm:"cover" vd:"len($)>0;msg:'请上传xxxx'"`
FieldName4 int `json:"openness" xorm:"openness" vd:"@:$>=1 && $<=3;msg:'请选择开xxxx'"`
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, tagexpr is powerful but the examples use so many variables like
a
b
c
d
, which is not meaningful.I suggest using some true scenario of any kind, say: validate an amount, email, phoneno, etc, which is more interesting and demonstrate the idea.
The text was updated successfully, but these errors were encountered: