request

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

MaxRequestBodySize is the maximum allowed size for request bodies (1MB 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. This is useful when you want to decode into an existing variable. The request 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)

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