validations

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Validations = "_validations"
	Errors      = "_errors"
)

Constants for the struct fields validations

Variables

View Source
var (
	NilDataError       = errors.New("data cannot be nil")
	NilMapperError     = errors.New("mapper cannot be nil")
	FieldNotFoundError = errors.New("field not found")
)

Functions

This section is empty.

Types

type MapperValidations

type MapperValidations struct {
	FailedMapperValidations  *map[string][]error
	NestedMappersValidations *map[string]*MapperValidations
}

MapperValidations is a struct that holds the error messages for failed validations of a struct

func NewMapperValidations

func NewMapperValidations() *MapperValidations

NewMapperValidations creates a new MapperValidations struct

func ValidateMapperNilFields

func ValidateMapperNilFields(
	data interface{},
	mapper *mapper.Mapper,
	mode *goflagsmode.Flag,
) (mapperValidations *MapperValidations, err error)

ValidateMapperNilFields validates if the fields are not nil

func (*MapperValidations) AddFailedFieldValidationError

func (s *MapperValidations) AddFailedFieldValidationError(validationName string, validationError error)

AddFailedFieldValidationError adds a failed field validation error to the struct

func (*MapperValidations) FailedValidationsMessage

func (s *MapperValidations) FailedValidationsMessage(level int) *string

FailedValidationsMessage returns a formatted error message for MapperValidations

func (*MapperValidations) GetLevelPadding

func (s *MapperValidations) GetLevelPadding(level int) string

GetLevelPadding returns the padding for the level

func (*MapperValidations) HasFailed

func (s *MapperValidations) HasFailed() bool

HasFailed returns true if there are failed validations

func (*MapperValidations) SetNestedMapperValidations

func (s *MapperValidations) SetNestedMapperValidations(
	validationName string,
	nestedStructFieldsValidations *MapperValidations,
)

SetNestedMapperValidations sets the nested struct fields validations to the struct

func (*MapperValidations) StringPtr added in v0.2.0

func (s *MapperValidations) StringPtr() *string

StringPtr returns a pointer to the failed validations message

Jump to

Keyboard shortcuts

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