httpform

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 12 Imported by: 1

README

httpform

Fill an input struct from Go net/http.Request body, cookies, query string and path params, transparently accept application/json, query string, application/x-www-form-urlencoded and multipart/form-data inputs

Documentation

Index

Constants

View Source
const MB = 1 << 20

MB is 1 megabyte in bytes, i.e. 1024 * 1024

Variables

View Source
var Default = &Configuration{
	AllowJSON:      true,
	AllowForm:      true,
	AllowMultipart: true,

	JSONBodyFallbackParam: "_body",

	MaxMultipartMemory: 32 * MB,

	DisallowUnknownFields: false,
}

Functions

func LimitBody

func LimitBody(w http.ResponseWriter, r *http.Request, maxSize int64)

func ParseBool

func ParseBool(str string) (bool, error)

ParseBool is similar to strconv.ParseBool, but recognizes on/off values that browsers send for checkboxes, and yes/no.

Types

type Configuration

type Configuration struct {
	AllowJSON      bool
	AllowForm      bool
	AllowMultipart bool

	JSONBodyFallbackParam string

	MaxMultipartMemory int64

	DisallowUnknownFields    bool
	AllowUnknownFieldsHeader string
	// contains filtered or unexported fields
}

func (*Configuration) Clone

func (conf *Configuration) Clone() *Configuration

func (*Configuration) Decode

func (conf *Configuration) Decode(r *http.Request, pathParams any, dest any) error

Decode ...

Warning: use LimitBody on request before calling Decode to avoid out-of-memory DoS attacks.

func (*Configuration) DecodeVal

func (conf *Configuration) DecodeVal(r *http.Request, pathParams any, destValPtr reflect.Value) error

DecodeVal ...

Warning: use LimitBody on request before calling DecodeVal to avoid out-of-memory DoS attacks.

func (*Configuration) EncodeToPath

func (conf *Configuration) EncodeToPath(source any, path string) string

func (*Configuration) EncodeToValues

func (conf *Configuration) EncodeToValues(source any, values url.Values)

EncodeToValues is a counterpart to Decode.

func (*Configuration) Strict

func (conf *Configuration) Strict() *Configuration

type Error

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

func (*Error) Error

func (e *Error) Error() string

func (*Error) HTTPCode

func (e *Error) HTTPCode() int

func (*Error) Message

func (e *Error) Message() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ParserFunc

type ParserFunc func(s string) (reflect.Value, error)

type StringerFunc

type StringerFunc func(v reflect.Value) (string, error)

Jump to

Keyboard shortcuts

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