validator

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 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(
	handler gonethttphandler.Handler,
	logger *slog.Logger,
) (*Middleware, error)

NewMiddleware creates a new Middleware instance

Parameters:

  • handler: The HTTP handler to parse the request body
  • 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 interface{},
	cache bool,
	auxiliaryValidatorFns ...interface{},
) (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
  • 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) Validate

func (m Middleware) Validate(
	body interface{},
	auxiliaryValidatorFns ...interface{},
) 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 interface{},
		cache bool,
		auxiliaryValidatorFns ...interface{},
	) (func(next http.Handler) http.Handler, error)
	Validate(
		body interface{},
		auxiliaryValidatorFns ...interface{},
	) 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