Documentation
¶
Overview ¶
Package validation implements a functional API for consistent struct level validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FieldError ¶
type FieldError struct { FieldPath string `json:"fieldPath"` FieldValue interface{} `json:"value"` Errors []string `json:"errors"` }
func NewFieldError ¶
func NewFieldError(fieldPath string, fieldValue interface{}, errs []error) *FieldError
func (FieldError) Error ¶
func (e FieldError) Error() string
func (FieldError) ValueString ¶
func (e FieldError) ValueString() string
type FieldRules ¶
type FieldRules[T, S any] struct { // contains filtered or unexported fields }
FieldRules is responsible for validating a single struct field.
func RulesForField ¶
func RulesForField[T, S any](fieldPath string, getter func(S) T) FieldRules[T, S]
RulesForField creates a typed FieldRules instance for the field which access is defined through getter function.
func (FieldRules[T, S]) If ¶
func (r FieldRules[T, S]) If(predicate func() bool) FieldRules[T, S]
func (FieldRules[T, S]) Validate ¶
func (r FieldRules[T, S]) Validate(st S) error
func (FieldRules[T, S]) With ¶
func (r FieldRules[T, S]) With(rules ...Rule[T]) FieldRules[T, S]
type MultiRule ¶
MultiRule allows defining Rule which aggregates multiple sub-rules.
func StringIsDNSSubdomain ¶
type SingleRule ¶
func StringDescription ¶
func StringDescription() SingleRule[string]
func StringLength ¶
func StringLength(min, max int) SingleRule[string]
func StringRequired ¶
func StringRequired() SingleRule[string]
func (SingleRule[T]) Validate ¶
func (r SingleRule[T]) Validate(v T) error
type StructRules ¶
type StructRules[S any] struct { // contains filtered or unexported fields }
func RulesForStruct ¶
func RulesForStruct[S any](rules ...fieldRules[S]) StructRules[S]
func (StructRules[S]) Validate ¶
func (r StructRules[S]) Validate(st S) []error
Click to show internal directories.
Click to hide internal directories.