validator

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTypeFunc

func RegisterTypeFunc(fn CustomTypeFunc, types ...any)

func RegisterValidationRules

func RegisterValidationRules(rules ...ValidationRule) error

func Validate

func Validate(value any) error

Types

type CustomTypeFunc

type CustomTypeFunc = func(field reflect.Value) any

type ValidationRule

type ValidationRule struct {
	// RuleTag is the struct-tag keyword that activates the rule (e.g. "dec_min"
	// for `validate:"dec_min=10"`). It must be unique across registered rules.
	RuleTag string
	// ErrMessageTemplate is the fallback message used when no i18n translation
	// resolves for ErrMessageI18nKey. It may contain {N} placeholders filled
	// from ParseParam in order ({0} is the first element, {1} the second).
	ErrMessageTemplate string
	// ErrMessageI18nKey is the i18n key looked up first to render the error
	// message; when it resolves, the translated text receives the same {N}
	// placeholder substitution as ErrMessageTemplate. Leave empty to always use
	// ErrMessageTemplate.
	ErrMessageI18nKey string
	// Validate reports whether the field value satisfies the rule. It returns
	// true when valid; the rule parameter (right of '=') is available via
	// fl.Param().
	Validate func(fl v.FieldLevel) bool
	// ParseParam returns the ordered substitution values for the message
	// placeholders ({0}, {1}, ...) for a failing field, typically the field
	// name and the rule parameter.
	ParseParam func(fe v.FieldError) []string
	// CallValidationEvenIfNull maps to go-playground's callEvenIfNull: when
	// true, Validate is invoked even for nil/zero fields. Leave false unless the
	// rule must inspect absent values.
	CallValidationEvenIfNull bool
}

ValidationRule describes a custom validation rule registered with the underlying go-playground validator. It is the extension point consumed by RegisterValidationRules: framework users populate one per custom constraint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL