Documentation ¶
Index ¶
- Constants
- Variables
- func ValidMailAddress(address string) (string, error)
- type StructFieldsToValidate
- type StructFieldsValidations
- func (s *StructFieldsValidations) AddFailedFieldValidationError(validationName string, validationError error)
- func (s *StructFieldsValidations) FailedValidationsMessage(level int) *string
- func (s *StructFieldsValidations) GetLevelPadding(level int) string
- func (s *StructFieldsValidations) HasFailed() bool
- func (s *StructFieldsValidations) SetNestedFieldsValidations(validationName string, nestedStructFieldsValidations *StructFieldsValidations)
- func (s *StructFieldsValidations) String() string
Constants ¶
const ( STATE = "state" SIZE_CACHE = "sizeCache" UNKNOWN_FIELDS = "unknownFields" )
Protobuf fields generated by the protoc compiler
Variables ¶
var ( MissingProtobufTagError = "missing protobuf tag: %s" MissingProtobufNameError = "missing protobuf name: %s" NilStructFieldsValidationsError = errors.New("nil struct fields validations") NilDataError = errors.New("nil data") NilStructFieldsToValidateError = errors.New("nil struct fields to validate") FieldNotFoundError = errors.New("field not found") InvalidBirthdateError = errors.New("invalid birthdate") InvalidMailAddressError = errors.New("invalid mail address") EmptyStringFieldError = errors.New("string field is empty") )
Functions ¶
func ValidMailAddress ¶
ValidMailAddress checks if the mail address is valid
Types ¶
type StructFieldsToValidate ¶
type StructFieldsToValidate struct { Fields map[string]string // Key is the field name and value is the name used in the validation error NestedStructFieldsToValidate map[string]*StructFieldsToValidate }
StructFieldsToValidate is a map of fields to validate from a struct
func CreateGRPCStructFieldsToValidate ¶
func CreateGRPCStructFieldsToValidate(exampleStruct interface{}, mode *commonflag.ModeFlag) ( *StructFieldsToValidate, error, )
CreateGRPCStructFieldsToValidate creates the fields to validate from a gRPC struct
type StructFieldsValidations ¶
type StructFieldsValidations struct { FailedFieldsValidations *map[string][]error NestedFieldsValidations *map[string]*StructFieldsValidations }
StructFieldsValidations is a struct that holds the error messages for failed validations of the fields of a struct
func NewStructFieldsValidations ¶
func NewStructFieldsValidations() *StructFieldsValidations
NewStructFieldsValidations creates a new StructFieldsValidations struct
func ValidateNilFields ¶
func ValidateNilFields( data interface{}, structFieldsToValidate *StructFieldsToValidate, ) (structFieldsValidations *StructFieldsValidations, err error)
ValidateNilFields validates if the fields are not nil
func (*StructFieldsValidations) AddFailedFieldValidationError ¶
func (s *StructFieldsValidations) AddFailedFieldValidationError(validationName string, validationError error)
AddFailedFieldValidationError adds a failed field validation error to the struct
func (*StructFieldsValidations) FailedValidationsMessage ¶
func (s *StructFieldsValidations) FailedValidationsMessage(level int) *string
FailedValidationsMessage returns a formatted error message for StructFieldsValidations
func (*StructFieldsValidations) GetLevelPadding ¶
func (s *StructFieldsValidations) GetLevelPadding(level int) string
GetLevelPadding returns the padding for the level
func (*StructFieldsValidations) HasFailed ¶
func (s *StructFieldsValidations) HasFailed() bool
HasFailed returns true if there are failed validations
func (*StructFieldsValidations) SetNestedFieldsValidations ¶
func (s *StructFieldsValidations) SetNestedFieldsValidations( validationName string, nestedStructFieldsValidations *StructFieldsValidations, )
SetNestedFieldsValidations sets the nested struct fields validations to the struct
func (*StructFieldsValidations) String ¶
func (s *StructFieldsValidations) String() string
String returns a formatted error message f