request

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxPageSize = 1000

MaxPageSize is the maximum allowed page size to prevent resource exhaustion.

View Source
var MaxRequestBodySize int64 = 5 << 20 // 5MB

MaxRequestBodySize is the maximum allowed size for request bodies (5MB default). This prevents resource exhaustion attacks from large payloads. Override this value if you need to accept larger requests.

Functions

func DecodeJSON added in v0.3.0

func DecodeJSON(r *http.Request, v any) error

DecodeJSON decodes JSON from the request body into the provided pointer. The body size is limited by MaxRequestBodySize to prevent DoS attacks.

func FormField

func FormField(r *http.Request, key string) (string, error)

func NumberParam

func NumberParam[T Number](r *http.Request, key string) (T, error)

NumberParam from request query string

func Payload

func Payload[T any](r *http.Request) (T, error)

func PayloadMap

func PayloadMap(r *http.Request) (map[string]any, error)

func PayloadWithValidate

func PayloadWithValidate[T any](r *http.Request) (T, error)

func QueryPayload added in v0.4.1

func QueryPayload[T any](r *http.Request) (T, error)

QueryPayload decodes URL query parameters into a value of type T. T must be a struct. Field names are taken from the `query` struct tag, falling back to the `json` tag, then the field name itself. Supported kinds are string, bool, signed and unsigned integers, floats, and slices of those types. Pointer fields are populated only when the corresponding key is present in the query string. Slice values may be supplied either by repeating the key (?id=1&id=2) or by a single comma-separated value (?id=1,2).

func QueryPayloadWithValidate added in v0.4.1

func QueryPayloadWithValidate[T any](r *http.Request) (T, error)

QueryPayloadWithValidate decodes query parameters into T and then runs struct validation via the validate package.

Types

type Number

type Number interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

type Pager

type Pager struct {
	OrderBy  *string `json:"orderBy"`
	OrderAsc *bool   `json:"orderAsc"`

	Search string

	Page  int `json:"page"`
	Size  int `json:"size"`
	Total int `json:"total"`

	TotalNeeded bool `json:"-"`
}

func GetPager

func GetPager(r *http.Request) Pager

GetPager info from request's query parameters

func (*Pager) HasSearch

func (i *Pager) HasSearch() bool

func (*Pager) Limit

func (i *Pager) Limit() int

func (*Pager) Offset

func (i *Pager) Offset() int

Jump to

Keyboard shortcuts

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