srv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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.

func WriteJSON

func WriteJSON(w http.ResponseWriter, r *http.Request, status int, payload any) error

WriteJSON writes payload as JSON with ACP response headers and status.

If the request includes an Idempotency-Key header, WriteJSON echoes it back in the response. A nil payload writes headers and status without a body.

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

type Mux struct {
	*http.ServeMux
}

Mux wraps http.ServeMux and routes handler errors through a shared ErrorHandler.

func NewMux

func NewMux(mux *http.ServeMux) *Mux

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.

Jump to

Keyboard shortcuts

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