Documentation
¶
Index ¶
- Variables
- func Binding(req *http.Request, params []BindingField) error
- func GetHeader(ctx context.Context, key string) string
- func GetReq(ctx context.Context) *http.Request
- func HandleJSON[Req, Resp Object](h JSONHandler[Req, Resp]) http.HandlerFunc
- func HandleStream[Req, Resp Object](h StreamHandler[Req, Resp]) http.HandlerFunc
- func ReadRequest(r *http.Request, i Object) error
- func SetCookie(ctx context.Context, cookie *http.Cookie)
- func SetHTTPCode(ctx context.Context, httpCode int)
- func SetHeader(ctx context.Context, key, value string)
- type BindingField
- type JSONHandler
- type Object
- type StreamHandler
Constants ¶
This section is empty.
Variables ¶
var HandleError = func(w http.ResponseWriter, err error) { http.Error(w, err.Error(), http.StatusInternalServerError) }
HandleError is the default error handler for failed requests.
Functions ¶
func Binding ¶
func Binding(req *http.Request, params []BindingField) error
Binding applies multiple BindingField rules to extract values from a request and bind them into a target object.
func HandleJSON ¶
func HandleJSON[Req, Resp Object](h JSONHandler[Req, Resp]) http.HandlerFunc
HandleJSON wraps a JSONHandler into an http.HandlerFunc.
func HandleStream ¶
func HandleStream[Req, Resp Object](h StreamHandler[Req, Resp]) http.HandlerFunc
HandleStream wraps a StreamHandler into an http.HandlerFunc. It supports server-sent event style streaming (SSE).
func ReadRequest ¶
ReadRequest parses the request body based on Content-Type and decodes it into the given Object.
func SetHTTPCode ¶
SetHTTPCode sets the HTTP response status code.
Types ¶
type BindingField ¶
type BindingField struct { Field string // Struct field name From string // "header", "path", or "query" Name string // Parameter name Target any // Target struct field pointer }
BindingField describes a mapping rule for extracting values from request headers, path parameters, or query parameters.
type JSONHandler ¶
type Object ¶
type Object interface { New() any // Returns a new instance of the object Binding(req *http.Request) error // Extracts additional values from the request Validate() error // Validates object fields }
Object defines the interface that all request/response types must implement.