12 lines
496 B
Go
12 lines
496 B
Go
|
|
// Package httputil provides typed HTTP handler adapters and response helpers.
|
||
|
|
//
|
||
|
|
// The centrepiece is [Handle], a generics-based adapter that wraps a pure Go
|
||
|
|
// function into an [net/http.HandlerFunc], handling JSON decode, validation,
|
||
|
|
// and error mapping automatically:
|
||
|
|
//
|
||
|
|
// r.Get("/orders/{id}", httputil.Handle(validator, svc.GetOrder))
|
||
|
|
//
|
||
|
|
// Error responses are mapped from [xerrors.Code] to HTTP status codes.
|
||
|
|
// All response helpers set Content-Type: application/json.
|
||
|
|
package httputil
|