Documentation ¶
Index ¶
- Variables
- type DefaultGenerator
- type DefaultValidations
- func (d *DefaultValidations) AddFailedFieldValidationError(validationName string, validationError error)
- func (d *DefaultValidations) GetFailedValidations() *map[string][]error
- func (d *DefaultValidations) GetNestedValidations() *map[string]Validations
- func (d *DefaultValidations) HasFailed() bool
- func (d *DefaultValidations) SetNestedValidations(validationName string, nestedValidations Validations)
- type DefaultValidator
- type Fields
- type Generator
- type Validations
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( NilDataError = errors.New("data cannot be nil") NilMapperError = errors.New("mapper cannot be nil") NilGeneratorError = errors.New("mapper validations generator cannot be nil") NilValidatorError = errors.New("mapper validator cannot be nil") NilValidationsError = errors.New("mapper validations cannot be nil") FieldNotFoundError = errors.New("field not found") )
var DefaultFields = NewFields("$validations", "$errors")
DefaultFields is the default fields names for the generated validations of a struct
Functions ¶
This section is empty.
Types ¶
type DefaultGenerator ¶
type DefaultGenerator struct {
Fields *Fields
}
DefaultGenerator is a struct that holds the default fields names for the generated validations of a struct
func NewDefaultGenerator ¶
func NewDefaultGenerator(fields *Fields) *DefaultGenerator
NewDefaultGenerator creates a new DefaultGenerator struct
func (*DefaultGenerator) Generate ¶
func (d *DefaultGenerator) Generate(validations Validations) ( message *string, err error, )
Generate returns a pointer to the failed validations message
func (*DefaultGenerator) GenerateFailedValidationsMessage ¶
func (d *DefaultGenerator) GenerateFailedValidationsMessage( validations Validations, level int, ) (*string, error)
GenerateFailedValidationsMessage returns a formatted error message for DefaultGenerator
func (*DefaultGenerator) GetLevelPadding ¶
func (d *DefaultGenerator) GetLevelPadding(level int) string
GetLevelPadding returns the padding for the level
type DefaultValidations ¶
type DefaultValidations struct { FailedValidations *map[string][]error NestedValidations *map[string]Validations }
DefaultValidations is a struct that holds the error messages for failed validations of a struct
func NewDefaultValidations ¶
func NewDefaultValidations() *DefaultValidations
NewDefaultValidations creates a new DefaultValidations struct
func (*DefaultValidations) AddFailedFieldValidationError ¶
func (d *DefaultValidations) AddFailedFieldValidationError( validationName string, validationError error, )
AddFailedFieldValidationError adds a failed field validation error to the struct
func (*DefaultValidations) GetFailedValidations ¶
func (d *DefaultValidations) GetFailedValidations() *map[string][]error
GetFailedValidations returns the failed fields validations
func (*DefaultValidations) GetNestedValidations ¶
func (d *DefaultValidations) GetNestedValidations() *map[string]Validations
GetNestedValidations returns the nested struct fields validations
func (*DefaultValidations) HasFailed ¶
func (d *DefaultValidations) HasFailed() bool
HasFailed returns true if there are failed validations
func (*DefaultValidations) SetNestedValidations ¶
func (d *DefaultValidations) SetNestedValidations( validationName string, nestedValidations Validations, )
SetNestedValidations sets the nested struct fields validations to the struct
type DefaultValidator ¶
type DefaultValidator struct {
// contains filtered or unexported fields
}
DefaultValidator struct
func NewDefaultValidator ¶
func NewDefaultValidator( mode *goflagsmode.Flag, ) *DefaultValidator
NewDefaultValidator creates a new default mapper validator
func (*DefaultValidator) ValidateNilFields ¶ added in v0.3.2
func (d *DefaultValidator) ValidateNilFields( data interface{}, mapper *mapper.Mapper, ) (validations Validations, err error)
ValidateNilFields validates if the fields are not nil
type Fields ¶
Fields is a struct that holds the fields names for the generated validations of a struct
type Generator ¶
type Generator interface { GetLevelPadding(level int) string GenerateFailedValidationsMessage( validations Validations, level int, ) (*string, error) Generate(validations Validations) (*string, error) }
Generator is an interface for generating struct fields validations
type Validations ¶
type Validations interface { HasFailed() bool AddFailedFieldValidationError( validationName string, validationError error, ) SetNestedValidations( validationName string, nestedValidations Validations, ) GetFailedValidations() *map[string][]error GetNestedValidations() *map[string]Validations }
Validations interface is an interface for struct fields validations