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

How to validate slice of struct field #88

Open
bhill77 opened this issue Feb 5, 2020 · 3 comments
Open

How to validate slice of struct field #88

bhill77 opened this issue Feb 5, 2020 · 3 comments

Comments

@bhill77
Copy link

bhill77 commented Feb 5, 2020

If I have struct like this:

type Contact struct {
	Type string `json:"type"`
	Value string `json:"value"`
}

type User struct {
	Name string `json:"name"`
	Contacts []Contact `json:"contacts"`
}

How to validate contact Type and value?

@feildrixliemdra
Copy link

hi @bhill77 did you got the answer for this?

@bhill77
Copy link
Author

bhill77 commented Feb 9, 2021

hi @bhill77 did you got the answer for this?

I iterate the slice and validate in the loop. I think this library doesn't support slice validation

@thedevsaddam
Copy link
Owner

Please use custom validation rules. Library supports length, required etc for slice

https://github.com/thedevsaddam/govalidator/blob/master/doc/CUSTOM_RULE.md

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

3 participants