validator

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: GPL-3.0 Imports: 11 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 Middleware

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

Middleware struct is the validation middleware

func NewMiddleware

func NewMiddleware(
	requestsHandler gonethttphandler.RequestsHandler,
	birthdateOptions *govalidatormappervalidator.BirthdateOptions,
	passwordOptions *govalidatormappervalidator.PasswordOptions,
	logger *slog.Logger,
) (*Middleware, error)

NewMiddleware creates a new Middleware instance

Parameters:

  • requestsHandler: The HTTP handler to parse the request body
  • birthdateOptions: The birthdate options (can be nil)
  • passwordOptions: The password options (can be nil)
  • logger: The logger (can be nil)

Returns:

  • *Middleware: The middleware instance
  • error: The error if any

func (Middleware) CreateValidateFn added in v0.10.4

func (m Middleware) CreateValidateFn(
	bodyExample any,
	decode bool,
	cache bool,
	auxiliaryValidatorFns ...any,
) (func(next http.Handler) http.Handler, error)

CreateValidateFn validates the request body and stores it in the context

Parameters:

  • bodyExample: An example of the body to validate
  • decode: Whether to decode the body or not
  • cache: Whether to cache the validation function or not
  • auxiliaryValidatorFns: Optional auxiliary validator functions

Returns:

  • func(next http.Handler) http.Handler: the validation middleware
  • error: if there was an error creating the validation function

func (Middleware) DecodeAndValidate added in v0.11.3

func (m Middleware) DecodeAndValidate(
	body any,
	auxiliaryValidatorFns ...any,
) func(next http.Handler) http.Handler

DecodeAndValidate decodes and validates the request body and stores it in the context

Parameters:

  • body: The body to decode and validate
  • auxiliaryValidatorFns: Optional auxiliary validator functions

Returns:

  • func(next http.Handler) http.Handler: the validation middleware

func (Middleware) Validate

func (m Middleware) Validate(
	body any,
	auxiliaryValidatorFns ...any,
) func(next http.Handler) http.Handler

Validate validates the request body and stores it in the context

Parameters:

  • body: The body to validate
  • auxiliaryValidatorFns: Optional auxiliary validator functions

Returns:

  • func(next http.Handler) http.Handler: the validation middleware

type Validator

type Validator interface {
	CreateValidateFn(
		body any,
		decode bool,
		cache bool,
		auxiliaryValidatorFns ...any,
	) (func(next http.Handler) http.Handler, error)
	Validate(
		body any,
		auxiliaryValidatorFns ...any,
	) func(next http.Handler) http.Handler
	DecodeAndValidate(
		body any,
		auxiliaryValidatorFns ...any,
	) func(next http.Handler) http.Handler
}

Validator interface

Jump to

Keyboard shortcuts

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