httpform

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyTooLarge = errors.New("request body too large")

Functions

func BindAndValidate

func BindAndValidate[T any](
	w http.ResponseWriter,
	r *http.Request,
	dst *T,
	schema form.Schema[T],
	maxBytes int64,
) bool

func BindAndValidateFlat

func BindAndValidateFlat[T any](
	w http.ResponseWriter,
	r *http.Request,
	dst *T,
	schema form.Schema[T],
	maxBytes int64,
) bool

func BindAndValidateWithOptions

func BindAndValidateWithOptions[T any](
	w http.ResponseWriter,
	r *http.Request,
	dst *T,
	schema form.Schema[T],
	maxBytes int64,
	opts ResponseOptions,
) bool

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any, maxBytes int64) error

func DecodeJSONLoose

func DecodeJSONLoose(w http.ResponseWriter, r *http.Request, dst any, maxBytes int64) error

func ValidateJSON

func ValidateJSON[T any](w http.ResponseWriter, r *http.Request, dst *T, schema form.Schema[T], maxBytes int64) (form.Errors, error)

func ValidateJSONLoose

func ValidateJSONLoose[T any](w http.ResponseWriter, r *http.Request, dst *T, schema form.Schema[T], maxBytes int64) (form.Errors, error)

func WriteValidationErrors

func WriteValidationErrors(w http.ResponseWriter, errs form.Errors)

func WriteValidationErrorsFlat

func WriteValidationErrorsFlat(w http.ResponseWriter, errs form.Errors)

Types

type ErrorFormat

type ErrorFormat string
const (
	ErrorFormatMap  ErrorFormat = "map"
	ErrorFormatFlat ErrorFormat = "flat"
)

type ResponseOptions

type ResponseOptions struct {
	ErrorFormat        ErrorFormat
	ValidationMessage  string
	InvalidJSONMessage string
	UniqueCodes        bool
}

func DefaultResponseOptions

func DefaultResponseOptions() ResponseOptions

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Message string                 `json:"message,omitempty"`
	Errors  map[string][]form.Code `json:"errors,omitempty"`
}

type ValidationFlatErrorResponse

type ValidationFlatErrorResponse struct {
	Message string           `json:"message,omitempty"`
	Errors  []form.ErrorItem `json:"errors,omitempty"`
}

Jump to

Keyboard shortcuts

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