request

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accepts

func Accepts(r *http.Request, contentType string) bool

Accepts checks if the request accepts a given content type.

func All

func All(r *http.Request) map[string]any

All returns a merged map of all input data (JSON wins over form, form wins over query).

func Boolean

func Boolean(r *http.Request, key string) bool

Boolean returns the input value as bool (accepts "1", "true", "on", "yes").

func Collect

func Collect(r *http.Request, keys ...string) *collection.Collection[any]

Collect returns selected (or all) input as a generic Collection.

func Except

func Except(r *http.Request, keys ...string) map[string]any

Except returns all input except the given keys.

func ExpectsJson

func ExpectsJson(r *http.Request) bool

ExpectsJson returns true if the client expects a JSON response (Accept or X-Requested-With).

func File

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

File returns the uploaded file for the given key.

func Float

func Float(r *http.Request, key string) float64

Float returns the input value as float64 (0 on failure).

func Has

func Has(r *http.Request, key string) bool

Has checks if an input value exists and is not empty.

func HasFile

func HasFile(r *http.Request, key string) bool

HasFile checks if a file was uploaded with the given key.

func Input

func Input(r *http.Request, key string) string

Input gets an input value from JSON body, form body, or query string (in that priority order).

func Integer

func Integer(r *http.Request, key string) int

Integer returns the input value as int (0 on failure).

func Old

func Old(r *http.Request, key string, defaultValue ...string) string

Old retrieves old input flashed from the previous request. It first checks the request context (if middleware stored it), then falls back to empty string. Full integration with session flash is done via middleware/session.go + session.Manager.Old().

func Only

func Only(r *http.Request, keys ...string) map[string]any

Only returns only the specified keys from all inputs.

func Param

func Param(r *http.Request, key string) string

Param gets a URL path parameter from the router context.

func Post

func Post(r *http.Request, key string) string

Post gets a value from the POST body (form data only, not JSON).

func Query

func Query(r *http.Request, key string) string

Query gets a query string value.

func Validate

func Validate(r *http.Request, form FormRequest) (map[string][]error, bool)

Validate executes authorization and validation against the HTTP request. Supports both form-urlencoded and JSON request bodies.

func WantsJson

func WantsJson(r *http.Request) bool

WantsJson is an alias for ExpectsJson (Laravel naming).

Types

type FormRequest

type FormRequest interface {
	Authorize() bool
	Rules() map[string][]string
}

FormRequest is the base interface for form validation requests. Only Authorize() and Rules() are required. Other methods are optional and checked via type assertions.

type FormRequestAttributes

type FormRequestAttributes interface {
	Attributes() map[string]string
}

FormRequestAttributes provides custom attribute names for errors.

type FormRequestFailed

type FormRequestFailed interface {
	FailedValidation(errors map[string][]error)
}

FormRequestFailed is called after failed validation.

type FormRequestMessages

type FormRequestMessages interface {
	Messages() map[string]string
}

FormRequestMessages provides custom validation messages.

type FormRequestPassed

type FormRequestPassed interface {
	PassedValidation()
}

FormRequestPassed is called after successful validation.

type FormRequestPrepare

type FormRequestPrepare interface {
	PrepareForValidation(data map[string]any) map[string]any
}

FormRequestPrepare allows modifying data before validation.

Jump to

Keyboard shortcuts

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