validator

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

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

type ValidateFn func(request any) error

ValidateFn func type for validating a value

Jump to

Keyboard shortcuts

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