validator

package
v0.5.31 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 BirthdateOptions added in v0.5.30

type BirthdateOptions struct {
	MinimumAge int
	MaximumAge int
}

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

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

func (*DefaultService) CreateValidateFn added in v0.5.24

func (d *DefaultService) CreateValidateFn(
	mapper *govalidatormapper.Mapper,
	auxiliaryValidatorFns ...interface{},
) (
	func(
		dest interface{},
	) (interface{}, error), error,
)

CreateValidateFn creates a validate function for the request body using the validator functions provided. It validates the required fields by default

The auxiliary validator function should have the following signature:

func(dest *RequestType, validations *govalidatormappervalidation.StructValidations) error

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

func (*DefaultService) ParseValidations

func (d *DefaultService) ParseValidations(
	rootStructValidations *govalidatormappervalidation.StructValidations,
) (interface{}, error)

ParseValidations parses 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

func (*DefaultService) Username added in v0.5.31

func (d *DefaultService) Username(
	usernameField string,
	username string,
	validations *govalidatormappervalidation.StructValidations,
)

Username validates the username field

func (*DefaultService) ValidateRequiredFields

func (d *DefaultService) ValidateRequiredFields(
	rootStructValidations *govalidatormappervalidation.StructValidations,
	mapper *govalidatormapper.Mapper,
) error

ValidateRequiredFields validates the required fields

type DefaultValidator

type DefaultValidator struct {
	// contains filtered or unexported fields
}

DefaultValidator struct

func NewDefaultValidator

func NewDefaultValidator(
	logger *Logger,
) *DefaultValidator

NewDefaultValidator creates a new default mapper validator

func (*DefaultValidator) IsFieldInitialized

func (d *DefaultValidator) IsFieldInitialized(
	fieldValue reflect.Value,
) (isInitialized bool)

IsFieldInitialized checks if a field is initialized

func (*DefaultValidator) ValidateRequiredFields

func (d *DefaultValidator) ValidateRequiredFields(
	rootStructValidations *govalidatormappervalidations.StructValidations,
	mapper *govalidatormapper.Mapper,
) error

ValidateRequiredFields validates the required fields of a struct

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is the structs mapper validator logger

func NewLogger

func NewLogger(header string, modeLogger gologgermode.Logger) (*Logger, error)

NewLogger creates a new structs mapper validator logger

func (*Logger) FieldTagNameNotFound added in v0.5.15

func (l *Logger) FieldTagNameNotFound(
	structTypeName, fieldName string,
	fieldType reflect.Type,
	fieldValue interface{},
)

FieldTagNameNotFound prints the field tag name not found on debug mode

func (*Logger) InitializedField

func (l *Logger) InitializedField(
	structTypeName,
	fieldName string,
	fieldType reflect.Type,
	fieldValue interface{},
	required bool,
)

InitializedField prints the initialized field on debug mode

func (*Logger) UninitializedField

func (l *Logger) UninitializedField(
	structTypeName, fieldName string,
	fieldType reflect.Type,
	required bool,
)

UninitializedField prints the uninitialized field on debug mode

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 ...interface{},
	) (
		func(
			dest interface{},
		) (interface{}, error), error,
	)
}

Service interface for the validator service

type Validator

type Validator interface {
	ValidateRequiredFields(
		rootStructValidations *govalidatormappervalidations.StructValidations,
		mapper *govalidatormapper.Mapper,
	) (err error)
}

Validator interface

Jump to

Keyboard shortcuts

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