Skip to content
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

Open
huahuayu opened this issue May 16, 2019 · 3 comments
Open

example improvement suggestion #7

huahuayu opened this issue May 16, 2019 · 3 comments

Comments

@huahuayu
Copy link

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.

@zhu327
Copy link

zhu327 commented Aug 9, 2019

suggest add some examples of Gin with tagexpr

@andeya
Copy link
Member

andeya commented Aug 12, 2019

No problem!

@mimicode
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants