validator

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterNullValueTypeFunc

func RegisterNullValueTypeFunc[T any]()

RegisterNullValueTypeFunc registers a type function for null.Value[T] types.

func RegisterTypeFunc

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

RegisterTypeFunc registers a custom type function for specified types.

func RegisterValidationRules

func RegisterValidationRules(rules ...ValidationRule) error

RegisterValidationRules registers custom validation rules.

func Validate

func Validate(value any) error

Validate validates the value.

Types

type CustomTypeFunc

type CustomTypeFunc = func(field reflect.Value) any

CustomTypeFunc defines a custom type function for validation that extracts values from custom types.

type ValidationRule

type ValidationRule struct {
	RuleTag                  string                         // RuleTag is the unique identifier for the validation rule (used in struct tags)
	ErrMessageTemplate       string                         // ErrMessageTemplate is the error message template with placeholders like {0}, {1}
	Validate                 func(fl v.FieldLevel) bool     // Validate performs the actual validation logic and returns true if valid
	ParseParam               func(fe v.FieldError) []string // ParseParam extracts parameters from FieldError for error message formatting
	CallValidationEvenIfNull bool                           // CallValidationEvenIfNull determines whether to validate nil/zero values
}

ValidationRule defines a custom validation rule with translation support.

Jump to

Keyboard shortcuts

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