Documentation
¶
Index ¶
- Variables
- type DefaultService
- func (d DefaultService) Birthdate(birthdateField string, birthdate time.Time, ...)
- func (d DefaultService) CreateValidateFn(requestExample any, cache bool, auxiliaryValidatorFns ...any) (ValidateFn, error)
- func (d DefaultService) Email(emailField string, email string, ...)
- func (d DefaultService) Password(passwordField string, password string, ...)
- func (d DefaultService) Username(usernameField string, username string, ...)
- func (d DefaultService) Validate(request any, auxiliaryValidatorFns ...any) error
- type Service
- type ValidateFn
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNilValidator = errors.New("validator is nil")
)
Functions ¶
This section is empty.
Types ¶
type DefaultService ¶
type DefaultService struct {
// contains filtered or unexported fields
}
DefaultService is the default struct validator service
func NewService ¶
func NewService( birthdateOptions *govalidatormappervalidator.BirthdateOptions, passwordOptions *govalidatormappervalidator.PasswordOptions, logger *slog.Logger, ) (*DefaultService, error)
NewService creates a new validator service
Parameters:
- birthdateOptions: the default birthdate options (optional, can be nil)
- passwordOptions: the default password options (optional, can be nil)
- logger: the logger
Returns:
- *Validator: the validator
- error: if there was an error creating the validator service
func (DefaultService) Birthdate ¶
func (d DefaultService) Birthdate( birthdateField string, birthdate time.Time, validations *govalidatormappervalidation.StructValidations, )
Birthdate validates a birthdate field
Parameters:
- birthdateField: the name of the birthdate field
- birthdate: the birthdate to validate
- validations: the struct validations
func (DefaultService) CreateValidateFn ¶
func (d DefaultService) CreateValidateFn( requestExample any, cache bool, auxiliaryValidatorFns ...any, ) (ValidateFn, error)
CreateValidateFn creates a validate function for a given request example
Parameters:
- requestExample: an example of the request to validate
- cache: whether to cache the validate function or not
- auxiliaryValidatorFns: auxiliary validator functions to use in the validation
Returns:
- ValidateFn: the validate function
- error: if there was an error creating the validate function
func (DefaultService) Email ¶
func (d DefaultService) Email( emailField string, email string, validations *govalidatormappervalidation.StructValidations, )
Email validates an email field
Parameters:
- emailField: the name of the email field
- email: the email to validate
- validations: the struct validations
func (DefaultService) Password ¶
func (d DefaultService) Password( passwordField string, password string, validations *govalidatormappervalidation.StructValidations, )
Password validates a password field
Parameters:
- passwordField: the name of the password field
- password: the password to validate
- validations: the struct validations
func (DefaultService) Username ¶
func (d DefaultService) Username( usernameField string, username string, validations *govalidatormappervalidation.StructValidations, )
Username validates a username field
Parameters:
- usernameField: the name of the username field
- username: the username to validate
- validations: the struct validations
func (DefaultService) Validate ¶ added in v0.3.3
func (d DefaultService) Validate( request any, auxiliaryValidatorFns ...any, ) error
Validate is the function that creates (if not cached), caches and executes the validation
Parameters:
- request: the request to validate
- auxiliaryValidatorFns: auxiliary validator functions to use in the validation
Returns:
- error: if there was an error validating the request
type Service ¶
type Service interface {
Email(
emailField string,
email string,
validations *validation.StructValidations,
)
Username(
usernameField string,
username string,
validations *validation.StructValidations,
)
Birthdate(
birthdateField string,
birthdate time.Time,
validations *validation.StructValidations,
)
Password(
passwordField string,
password string,
validations *validation.StructValidations,
)
CreateValidateFn(
requestExample any,
cache bool,
auxiliaryValidatorFns ...any,
) (ValidateFn, error)
Validate(
request any,
auxiliaryValidatorFns ...any,
) error
}
Service interface
type ValidateFn ¶ added in v0.3.2
ValidateFn func type for validating a value
Click to show internal directories.
Click to hide internal directories.