Documentation
¶
Index ¶
- func DecodeJSON(body io.ReadCloser, v any) error
- func WriteACPError(w http.ResponseWriter, err *acp.Error) error
- func WriteError(w http.ResponseWriter, status int, payload any) error
- func WriteJSON(w http.ResponseWriter, r *http.Request, status int, payload any) error
- type ErrorHandler
- type HandlerFunc
- type Middleware
- type Mux
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func DecodeJSON(body io.ReadCloser, v any) error
DecodeJSON decodes exactly one JSON value from body into v and closes body.
It returns an error if the body is empty, contains invalid JSON, or contains extra trailing JSON data after the first value.
func WriteACPError ¶
func WriteACPError(w http.ResponseWriter, err *acp.Error) error
WriteACPError writes err as a JSON response with its status and retry headers.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, payload any) error
WriteError writes payload as JSON with ACP error response headers and status.
Types ¶
type ErrorHandler ¶
type ErrorHandler func(http.ResponseWriter, *http.Request, error)
ErrorHandler handles an error returned from a HandlerFunc.
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
HandlerFunc handles an HTTP request and returns any error that should be processed by an ErrorHandler.
type Middleware ¶
type Middleware func(http.ResponseWriter, *http.Request, HandlerFunc) error
Middleware wraps a HandlerFunc with additional request processing.
func AuthorizationMiddleware ¶
func AuthorizationMiddleware(authorizer acpauth.Authorizer) Middleware
AuthorizationMiddleware validates the Authorization header and authorizes its bearer token before calling next.
func IdempotencyMiddleware ¶
func IdempotencyMiddleware() Middleware
IdempotencyMiddleware enforces the ACP Idempotency-Key contract for mutating routes.
func RequestContextMiddleware ¶
func RequestContextMiddleware() Middleware
RequestContextMiddleware validates ACP request headers and stores the resulting acp.RequestContext on the request context passed to next.
type Mux ¶
Mux wraps http.ServeMux and routes handler errors through a shared ErrorHandler.
func NewMux ¶
NewMux returns a Mux that dispatches handler errors to handleError.
It panics if handleError is nil.
func (*Mux) HandleFunc ¶
func (m *Mux) HandleFunc(pattern string, f HandlerFunc, middleware ...Middleware)
HandleFunc registers pattern with a handler that may return an error.
If the handler returns a non-nil error, the mux forwards it to the ErrorHandler provided to NewMux. Middleware is applied in the order it is provided.