options.go 1011 B

1234567891011121314151617181920212223242526
  1. package validator
  2. // Option represents a configurations option to be applied to validator during initialization.
  3. type Option func(*Validate)
  4. // WithRequiredStructEnabled enables required tag on non-pointer structs to be applied instead of ignored.
  5. //
  6. // This was made opt-in behaviour in order to maintain backward compatibility with the behaviour previous
  7. // to being able to apply struct level validations on struct fields directly.
  8. //
  9. // It is recommended you enabled this as it will be the default behaviour in v11+
  10. func WithRequiredStructEnabled() Option {
  11. return func(v *Validate) {
  12. v.requiredStructEnabled = true
  13. }
  14. }
  15. // WithPrivateFieldValidation activates validation for unexported fields via the use of the `unsafe` package.
  16. //
  17. // By opting into this feature you are acknowledging that you are aware of the risks and accept any current or future
  18. // consequences of using this feature.
  19. func WithPrivateFieldValidation() Option {
  20. return func(v *Validate) {
  21. v.privateFieldValidation = true
  22. }
  23. }