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 can validate slice off map? #206

Closed
mdsohelmia opened this issue May 9, 2023 · 2 comments
Closed

How can validate slice off map? #206

mdsohelmia opened this issue May 9, 2023 · 2 comments
Labels
bug_fixed bug Something isn't working

Comments

@mdsohelmia
Copy link

mdsohelmia commented May 9, 2023

How can validate slice off map?

Golang Code

validate.Config(func(opt *validate.GlobalOption) {
		opt.StopOnError = false
		opt.SkipOnEmpty = false
	})

	m := map[string]interface{}{
		"name":  "inhere",
		"age":   99,
		"oldSt": 10,
		"newSt": 10,
		"email": "some@email.com",
		"tags":  []string{"go", "php", "java"},
		"origins": []map[string]string{
			{"name": "test", "url": "https://test.com"},
			{"name": "test", "url": "https://test.com"},
		},
	}

	v := validate.Map(m)
	// can also
	v.StringRule("age", "required|int|min:1|max:99")
	v.StringRule("name", "required|minLen:2")
	v.StringRule("tags", "required|slice|minlen:1")
	// feat: support check sub-item in slice
	v.StringRule("tags.*", "required|string|min_len:1")
	v.StringRule("origins", "required|slice|minlen:1")
	v.StringRule("origins.*.name", "required|full_url")

Get errors:

{
  "origins.*.name": {
    "_validate": "cannot convert map to arg#0(string), validator 'isFullURL'",
    "full_url":  "origins.*.name must be a valid full URL address",
  },
}

"cannot convert map to arg#0(string), validator 'isFullURL'"

@inhere inhere added the question Further information is requested label May 10, 2023
@inhere inhere added bug Something isn't working resolved bug_fixed and removed question Further information is requested resolved labels Jul 31, 2023
@inhere
Copy link
Member

inhere commented Jul 31, 2023

hi @mdsohelmia Thanks for your bug report. Bug fixes will be released in the next version.

@inhere
Copy link
Member

inhere commented Aug 1, 2023

@inhere inhere closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug_fixed bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants