Documentation
¶
Index ¶
- Variables
- type Middleware
- func (m Middleware) CreateValidateFn(bodyExample any, decode bool, cache bool, auxiliaryValidatorFns ...any) (func(next http.Handler) http.Handler, error)
- func (m Middleware) DecodeAndValidate(body any, auxiliaryValidatorFns ...any) func(next http.Handler) http.Handler
- func (m Middleware) Validate(body any, auxiliaryValidatorFns ...any) func(next http.Handler) http.Handler
- type Validator
Constants ¶
This section is empty.
Variables ¶
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 NewJSONMiddleware ¶ added in v0.13.9
func NewJSONMiddleware( requestsHandler gonethttphandler.RequestsHandler, birthdateOptions *govalidatormappervalidator.BirthdateOptions, passwordOptions *govalidatormappervalidator.PasswordOptions, logger *slog.Logger, ) (*Middleware, error)
NewJSONMiddleware creates a new Middleware instance for JSON requests
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 NewMiddleware ¶
func NewMiddleware( requestsHandler gonethttphandler.RequestsHandler, generator govalidatormapper.Generator, 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
- generator: The validator mapper generator
- 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 NewProtoJSONMiddleware ¶ added in v0.13.9
func NewProtoJSONMiddleware( requestsHandler gonethttphandler.RequestsHandler, birthdateOptions *govalidatormappervalidator.BirthdateOptions, passwordOptions *govalidatormappervalidator.PasswordOptions, logger *slog.Logger, ) (*Middleware, error)
NewProtoJSONMiddleware creates a new Middleware instance for ProtoJSON requests
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