req

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package req provides HTTP request parsing, validation, and input binding utilities.

It supports automatic parsing of request data from various sources (JSON, form data, query parameters, headers) into Go structs with validation support. The package integrates with httpin for flexible input binding and provides validation interfaces for request data validation.

Index

Constants

View Source
const InKey = "input"

Variables

This section is empty.

Functions

func DecodeJSONBody

func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst any) error

func HasFormData

func HasFormData(r *http.Request) bool

func HasFormUrlEncoded added in v0.1.5

func HasFormUrlEncoded(r *http.Request) bool

func HasJSON added in v0.1.5

func HasJSON(r *http.Request) bool

func HasMultiPart added in v0.1.5

func HasMultiPart(r *http.Request) bool

func In

func In(c Context, inputStruct any, opts ...core.Option) error

func ParseInput

func ParseInput(rr RequestResponder, inputStruct any, opts ...core.Option) error

func WantsHTML

func WantsHTML(r *http.Request) bool

func WantsJSON

func WantsJSON(r *http.Request) bool

func WantsXML added in v0.1.5

func WantsXML(r *http.Request) bool

Types

type Context

type Context interface {
	RequestResponder
	GetSetter
}

Context combines request/response access with key-value storage. This interface is typically implemented by HTTP context types.

type GetSetter

type GetSetter interface {
	Get(key string) any
	Set(key string, value any)
}

GetSetter provides key-value storage for request-scoped data. This allows storing and retrieving arbitrary values during request processing.

type MalformedRequest

type MalformedRequest struct {
	Status  int
	Message string
}

func (*MalformedRequest) Error

func (mr *MalformedRequest) Error() string

type RequestResponder

type RequestResponder interface {
	Request() *http.Request
	ResponseWriter() http.ResponseWriter
}

RequestResponder provides access to HTTP request and response writer. This interface is typically implemented by framework context types.

type Validator

type Validator interface {
	Validate() error
}

Validator defines an interface for structs that can validate themselves. Types implementing this interface can provide custom validation logic.

Jump to

Keyboard shortcuts

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