asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.06k stars 556 forks source link

Error in validating map[string]interface{} struct field #454

Open dex80526 opened 3 years ago

dex80526 commented 3 years ago

Bug Report

The following struct:

type S struct { Props map[string]interface{} `valid:"required"` } d := S{props: map[string]interface{}{"field": "test"} result, err := valid.ValidateStruct(d) ...

With the above code, it gets an error: "function only accepts structs; got string;"

However, if the field of Props is private (i.e., props), the validation is skipped. Q A
Version(s) v0.0.0-20200428143746-21a406dcc535

Summary

The validator does not handle required field of map[string]interface{} correctly.

Current behavior

The current result: false with the error msg of "function only accepts structs; got string;"

How to reproduce

See the above sample code.

Expected behavior

The expected validation result: true (no error)