Documentation
¶
Index ¶
- type Coder
- type Config
- type Detailer
- type Handler
- type Layer
- type Mux
- type Option
- type Renderer
- type Response
- func Accepted[Res any](body *Res) *Response[Res]
- func Created[Res any](body *Res) *Response[Res]
- func HTML[Res any](status int, body *Res) *Response[Res]
- func JSON[Res any](status int, body *Res) *Response[Res]
- func NewJsonResponse[Res any](status int, body *Res) *Response[Res]
- func NewResponse[Res any](status int, body *Res) *Response[Res]
- func NoContent() *Response[any]
- func OK[Res any](body *Res) *Response[Res]
- func StreamWith(status int, contentType string, fn func(w io.Writer) error) *Response[any]
- func Text[Res any](status int, body *Res) *Response[Res]
- func XML[Res any](status int, body *Res) *Response[Res]
- type RouteMeta
- type Router
- type Server
- type Source
- type StatusError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxHeaderBytes int
ShutdownTimeout time.Duration
}
A zero is no timeout, ShutdownTimeout included: a hung shutdown is better seen than silently truncated.
type Layer ¶
Layer is a type alias so named function-typed middlewares (Compress, CustomerAuth, etc.) are assignable to Layer without explicit conversion.
type Mux ¶
type Mux interface {
http.Handler
Use(layers ...Layer)
// Group snapshots layers and prefix; parent and child diverge after.
Group(prefix string, layers ...Layer) Mux
Get(path string, layers ...Layer)
Post(path string, layers ...Layer)
Put(path string, layers ...Layer)
Patch(path string, layers ...Layer)
Delete(path string, layers ...Layer)
Handle(method, path string, layers ...Layer)
Routes() []RouteMeta
}
chi rather than stdlib ServeMux: radix-tree routing tolerates overlapping patterns (`/x/{id}` beside `/x/foo/{id}`) that ServeMux rejects.
type Option ¶
type Option func(*server)
func WithIdleTimeout ¶
func WithMaxHeaderBytes ¶
func WithReadHeaderTimeout ¶
func WithReadTimeout ¶
func WithShutdownTimeout ¶
func WithWriteTimeout ¶
type Renderer ¶
type Renderer interface {
Render(w http.ResponseWriter) error
WriteBody(w io.Writer) error
Status() int
Headers() http.Header
Body() any
Stream() func(w io.Writer) error
}
type Response ¶
type Response[Res any] struct { // contains filtered or unexported fields }
Response[Res]: set one of body or stream. status 0 → 200. nil receiver → 204.
func NewJsonResponse ¶
func NewResponse ¶
func StreamWith ¶
type RouteMeta ¶
type RouteMeta struct {
Method string
Path string
Req reflect.Type
Res reflect.Type
Handler uintptr
}
Req and Res are nil for a route registered through Handle, which takes an untyped handler and so contributes nothing to a specification.
type Source ¶
type Source interface {
scan.Source
Path(key string) string
Query(key string) string
QueryAll(key string) []string
Header(key string) string
HeaderAll(key string) []string
Cookie(key string) string
Form(key string) string
FormAll(key string) []string
Request() *http.Request
SetRequest(*http.Request)
}
The typed helpers are for what has no generated Parse: middlewares, and handlers written by hand.
type StatusError ¶
StatusError sets HTTP status. Errors without it default to 500.