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

Struct validation #12

Closed
amirkheirabadi73 opened this issue Dec 16, 2017 · 4 comments
Closed

Struct validation #12

amirkheirabadi73 opened this issue Dec 16, 2017 · 4 comments

Comments

@amirkheirabadi73
Copy link

amirkheirabadi73 commented Dec 16, 2017

I want to check validation struct instead *net.http. I can't find any sample code.
for example :

type user struct {
	Username string           `json:"username"`
	Email    string           `json:"email"`
	Web      string           `json:"web"`
	Age      govalidator.Int  `json:"age"`
	Agree    govalidator.Bool `json:"agree"`
}

rules := govalidator.MapData{
	"username": []string{"required", "between:3,8"},
	"email":    []string{"required", "min:4", "max:20", "email"},
	"web":      []string{"url"},
	"phone":    []string{"digits:11"}
	"agree":    []string{"bool"},
	"dob":      []string{"date"},
}

opts := govalidator.Options{
	Request:         &user{Username: "test",  ....},        // use struct instead net.http
	Rules:           rules,    // rules map
	Messages:        messages, // custom message map (Optional)
	RequiredDefault: true,     // all the field to be pass the rules
} 

how I can do this ?

@thedevsaddam
Copy link
Owner

@amirkheirabadi At this time there is no feature available for struct validation. I'll try to add this as new feature.

@amirkheirabadi73
Copy link
Author

thank you @thedevsaddam ,I'll add this feature to govalidator and then I'll send PR

@thedevsaddam
Copy link
Owner

@amirkheirabadi Sure 👍

@jkryanchou
Copy link

👍

maoueh pushed a commit to maoueh/govalidator that referenced this issue Feb 5, 2019
thedevsaddam pushed a commit that referenced this issue Mar 9, 2019
* Added `ValidateStruct` to validate a struct without a request (#57) (#58)

Fixes #12

* Update MAP_VALIDATION.md

Fixed typo
thedevsaddam pushed a commit that referenced this issue Jun 14, 2019
* Added `ValidateStruct` to validate a struct without a request (#57) (#58)

Fixes #12

* Update MAP_VALIDATION.md

Fixed typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants