Skip to content

Consider adding a new function to return reflection type #1357

@K1ender

Description

@K1ender
  • 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:

I encountered an issue when using the eqfield validator in the DTO struct. The eqfield parameter points to a field, but in the case of a validation error, it returns a string instead of a reflection type or a separate paramField. This makes it difficult to determine which field caused the error and to access its JSON tag.

Code sample, to showcase or reproduce:

var _validator = validator.New()

type DTO struct {
	Password        *string `json:"password" validate:"required,min=8"`
	PasswordConfirm *string `json:"password_confirm" validate:"required,eqfield=Password"`
}

func main() {
	password := "passwordpassword"
	password_confirm := "password_confirm"
	data := DTO{
		Password:        &password,
		PasswordConfirm: &password_confirm,
	}
	err := _validator.Struct(data)

	if err != nil {
		for _, err := range err.(validator.ValidationErrors) {
			fmt.Println(err.Param())
		}
	}
}
"password_confirm": [
        "password_confirm must be equal to Password"
]

I'm using en.RegisterDefaultTranslations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions