Documentation
¶
Index ¶
- Variables
- type AuxiliaryValidatorFn
- type BirthdateOptions
- type DefaultService
- func (d DefaultService) Birthdate(birthdateField string, birthdate time.Time, options *BirthdateOptions, ...)
- func (d DefaultService) CreateValidateFn(mapper *govalidatormapper.Mapper, ...) (ValidateFn, error)
- func (d DefaultService) Email(emailField string, email string, ...)
- func (d DefaultService) ParseValidations(rootStructValidations *govalidatormappervalidation.StructValidations) (interface{}, error)
- func (d DefaultService) Password(passwordField string, password string, options *PasswordOptions, ...)
- func (d DefaultService) Username(usernameField string, username string, ...)
- func (d DefaultService) ValidateRequiredFields(rootStructValidations *govalidatormappervalidation.StructValidations, ...) error
- type DefaultValidator
- type PasswordOptions
- type Service
- type ValidateFn
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilService = errors.New("mapper validator service cannot be nil") ErrNilDestination = errors.New("destination cannot be nil") ErrDestinationNotPointer = errors.New("destination must be a pointer") ErrNilMapper = errors.New("mapper cannot be nil") ErrNilValidator = errors.New("mapper validator cannot be nil") ErrFieldTagNameNotFound = "field tag name not found: %s" ErrFieldIsRequiredNotFound = "field is required not found: %s" ErrRequiredField = "%s is required" )
Functions ¶
This section is empty.
Types ¶
type AuxiliaryValidatorFn ¶ added in v0.6.0
type AuxiliaryValidatorFn func(
dest interface{},
validations *govalidatormappervalidation.StructValidations,
) error
AuxiliaryValidatorFn is the type for the auxiliary validator function
type BirthdateOptions ¶ added in v0.5.30
BirthdateOptions is the birthdate options struct
type DefaultService ¶
type DefaultService struct {
// contains filtered or unexported fields
}
DefaultService struct
func NewDefaultService ¶
func NewDefaultService( parser govalidatormapperparser.Parser, validator Validator, ) (*DefaultService, error)
NewDefaultService creates a new default validator service
Parameters:
- parser: the parser to use
- validator: the validator to use
Returns:
- *DefaultService: the default validator service
- error: if there was an error creating the service
func (DefaultService) Birthdate ¶ added in v0.5.26
func (d DefaultService) Birthdate( birthdateField string, birthdate time.Time, options *BirthdateOptions, validations *govalidatormappervalidation.StructValidations, )
Birthdate validates the birthdate field
Parameters:
- birthdateField: the birthdate field name - birthdate: the birthdate to validate - options: the birthdate options - validations: the struct validations
func (DefaultService) CreateValidateFn ¶ added in v0.5.24
func (d DefaultService) CreateValidateFn( mapper *govalidatormapper.Mapper, auxiliaryValidatorFns ...AuxiliaryValidatorFn, ) ( ValidateFn, error, )
CreateValidateFn creates a validate function for the request body using the validator functions provided. It validates the required fields by default
Parameters:
- mapper: the mapper to use
- auxiliaryValidatorFns: the auxiliary validator functions to use
Returns:
- ValidateFn: the validate function
- error: if there was an error creating the validate function
func (DefaultService) Email ¶ added in v0.5.26
func (d DefaultService) Email( emailField string, email string, validations *govalidatormappervalidation.StructValidations, )
Email validates the email address field
Parameters:
- emailField: the email field name
- email: the email to validate
- validations: the struct validations
func (DefaultService) ParseValidations ¶
func (d DefaultService) ParseValidations( rootStructValidations *govalidatormappervalidation.StructValidations, ) (interface{}, error)
ParseValidations parses the validations
Parameters:
- rootStructValidations: the root struct validations
Returns:
- interface{}: the parsed validations
- error: if there was an error parsing the validations
func (DefaultService) Password ¶ added in v0.5.30
func (d DefaultService) Password( passwordField string, password string, options *PasswordOptions, validations *govalidatormappervalidation.StructValidations, )
Password validates the password field
Parameters:
- passwordField: the password field name - password: the password to validate - options: the password options - validations: the struct validations
func (DefaultService) Username ¶ added in v0.5.31
func (d DefaultService) Username( usernameField string, username string, validations *govalidatormappervalidation.StructValidations, )
Username validates the username field
Parameters:
- usernameField: the username field name
- username: the username to validate
- validations: the struct validations
func (DefaultService) ValidateRequiredFields ¶
func (d DefaultService) ValidateRequiredFields( rootStructValidations *govalidatormappervalidation.StructValidations, mapper *govalidatormapper.Mapper, ) error
ValidateRequiredFields validates the required fields
Parameters:
- rootStructValidations: the root struct validations
- mapper: the mapper to use
Returns:
- error: if there was an error validating the required fields
type DefaultValidator ¶
type DefaultValidator struct {
// contains filtered or unexported fields
}
DefaultValidator struct
func NewDefaultValidator ¶
func NewDefaultValidator( logger *slog.Logger, ) *DefaultValidator
NewDefaultValidator creates a new default mapper validator
Parameters:
- logger: the logger to use
Returns:
- *DefaultValidator: the default mapper validator
func (DefaultValidator) IsFieldInitialized ¶
func (d DefaultValidator) IsFieldInitialized( fieldValue reflect.Value, ) (isInitialized bool)
IsFieldInitialized checks if a field is initialized
Parameters:
- fieldValue: the field value to check
Returns:
- isInitialized: true if the field is initialized, false otherwise
func (DefaultValidator) ValidateRequiredFields ¶
func (d DefaultValidator) ValidateRequiredFields( rootStructValidations *govalidatormappervalidations.StructValidations, mapper *govalidatormapper.Mapper, ) error
ValidateRequiredFields validates the required fields of a struct
Parameters:
- rootStructValidations: the root struct validations to validate
- mapper: the struct mapper to use
Returns:
- err: error if any
type PasswordOptions ¶ added in v0.5.30
type PasswordOptions struct {
MinimumLength int
MinimumSpecialCount int
MinimumNumbersCount int
MinimumCapsCount int
}
PasswordOptions is the password options struct
type Service ¶
type Service interface {
ValidateRequiredFields(
rootStructValidations *govalidatormappervalidation.StructValidations,
mapper *govalidatormapper.Mapper,
) error
ParseValidations(rootStructValidations *govalidatormappervalidation.StructValidations) (
interface{},
error,
)
Email(
emailField string,
email string,
validations *govalidatormappervalidation.StructValidations,
)
Username(
usernameField string,
username string,
validations *govalidatormappervalidation.StructValidations,
)
Birthdate(
birthdateField string,
birthdate time.Time,
options *BirthdateOptions,
validations *govalidatormappervalidation.StructValidations,
)
Password(
passwordField string,
password string,
options *PasswordOptions,
validations *govalidatormappervalidation.StructValidations,
)
CreateValidateFn(
mapper *govalidatormapper.Mapper,
auxiliaryValidatorFns ...AuxiliaryValidatorFn,
) (
ValidateFn, error,
)
}
Service interface for the validator service
type ValidateFn ¶ added in v0.6.0
type ValidateFn func(dest interface{}) (interface{}, error)
ValidateFn is the type for the validate function
type Validator ¶
type Validator interface {
ValidateRequiredFields(
rootStructValidations *govalidatormappervalidations.StructValidations,
mapper *govalidatormapper.Mapper,
) (err error)
}
Validator interface