validation

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: GPL-3.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilInstance          = errors.New("struct instance cannot be nil")
	ErrNilStructValidations = errors.New("struct validations is nil")
	ErrNilFieldValidations  = errors.New("field validations is nil")
)

Functions

This section is empty.

Types

type FieldValidations

type FieldValidations struct {
	// contains filtered or unexported fields
}

FieldValidations is a struct that holds the field validations for the generated validations of a struct

func NewFieldValidations

func NewFieldValidations() *FieldValidations

NewFieldValidations creates a new FieldValidations struct

Returns:

  • *FieldValidations: The FieldValidations struct

func (*FieldValidations) AddValidationError

func (f *FieldValidations) AddValidationError(
	validationError error,
)

AddValidationError adds a validation error to the field

Parameters:

  • validationError: The validation error to add

func (*FieldValidations) GetErrors

func (f *FieldValidations) GetErrors() []error

GetErrors returns the field errors

Returns:

  • []error: The field errors

func (*FieldValidations) HasFailed

func (f *FieldValidations) HasFailed() bool

HasFailed returns true if there are failed validations

Returns:

  • bool: True if there are failed validations, false otherwise

type StructValidations

type StructValidations struct {
	// contains filtered or unexported fields
}

StructValidations is a struct that holds the struct validations for the generated validations of a struct

func NewNestedStructValidations

func NewNestedStructValidations(
	fieldName string,
	instance any,
) (*StructValidations, error)

NewNestedStructValidations creates a new nested StructValidations struct

Parameters:

  • fieldName: The name of the field that holds the nested struct
  • instance: The instance of the nested struct to validate

Returns:

  • *StructValidations: The StructValidations struct
  • error: An error if the field name is empty or the instance is nil

func NewStructValidations

func NewStructValidations(instance any) (*StructValidations, error)

NewStructValidations creates a new StructValidations struct

Parameters:

  • instance: The instance of the struct to validate

Returns:

  • *StructValidations: The StructValidations struct
  • error: An error if the instance is nil

func (*StructValidations) AddFieldValidationError

func (s *StructValidations) AddFieldValidationError(
	fieldName string,
	validationError error,
)

AddFieldValidationError adds a validation error to the field

Parameters:

  • fieldName: The name of the field to add the validation error to
  • validationError: The validation error to add

func (*StructValidations) AddFieldValidations

func (s *StructValidations) AddFieldValidations(
	fieldName string,
	fieldValidations *FieldValidations,
)

AddFieldValidations sets the fields validations to the struct

Parameters:

  • fieldName: The name of the field to add the validations to
  • fieldValidations: The field validations to add

func (*StructValidations) AddNestedStructValidations

func (s *StructValidations) AddNestedStructValidations(
	fieldName string,
	nestedStructValidations *StructValidations,
)

AddNestedStructValidations sets the nested struct fields validations to the struct

Parameters:

  • fieldName: The name of the field that holds the nested struct
  • nestedStructValidations: The nested struct validations to add

func (*StructValidations) GetFieldsValidations

func (s *StructValidations) GetFieldsValidations() map[string]*FieldValidations

GetFieldsValidations returns the fields validations

Returns:

  • map[string]*FieldValidations: The fields validations

func (*StructValidations) GetNestedStructsValidations

func (s *StructValidations) GetNestedStructsValidations() map[string]*StructValidations

GetNestedStructsValidations returns the nested structs validations

Returns:

  • map[string]*StructValidations: The nested structs validations

func (*StructValidations) GetReflection

func (s *StructValidations) GetReflection() *goreflect.Reflection

GetReflection returns the reflection of the struct

Returns:

  • *goreflect.Reflection: The reflection of the struct

func (*StructValidations) GetStructTypeName

func (s *StructValidations) GetStructTypeName() string

GetStructTypeName returns the type name of the struct

Returns:

  • string: The type name of the struct

func (*StructValidations) GetUniqueTypeReference added in v0.7.1

func (s *StructValidations) GetUniqueTypeReference() *string

GetUniqueTypeReference returns the unique type reference of the struct

Returns:

  • *string: The unique type reference of the struct

func (*StructValidations) HasFailed

func (s *StructValidations) HasFailed() bool

HasFailed returns true if there are failed validations

Returns:

  • bool: True if there are failed validations, false otherwise

Jump to

Keyboard shortcuts

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