-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
- I have looked at the documentation here first?
- I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
Custom rule FieldLevel.FieldName() return empty string on Validate.ValidateMap()
Code sample, to showcase or reproduce:
main.go
package main
import (
"fmt"
"reflect"
"github.com/go-playground/validator/v10"
)
func main() {
validate := validator.New()
validate.RegisterTagNameFunc(func(field reflect.StructField) string {
fmt.Println("TagNameFunc")
return "test"
})
validate.RegisterValidation("presented", func(fl validator.FieldLevel) bool {
fmt.Println("presented")
fmt.Println("fl.FieldName()", fl.FieldName())
return false
}, true)
data := map[string]interface{}{
"field": "nil",
}
rule := map[string]interface{}{
"field": "presented",
}
result := validate.ValidateMap(data, rule)
fmt.Println("result", result)
err := result["field"]
fmt.Println(reflect.TypeOf(err))
fmt.Println(err)
}output:
presented
fl.FieldName()
result map[field:Key: '' Error:Field validation for '' failed on the 'presented' tag]
validator.ValidationErrors
Key: '' Error:Field validation for '' failed on the 'presented' tag
Expected
FieldLevel.FieldName() will return string "field" instead of empty string "".
kokoraka and advancevillageadvancevillage
Metadata
Metadata
Assignees
Labels
No labels