Documentation
¶
Overview ¶
Package http provides transport-independent HTTP responses, JSON decoding and application error mapping. Import it as pfwhttp alongside net/http.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func DecodeJSON[T any](r *stdhttp.Request, options DecodeOptions) (T, error)
DecodeJSON reads one JSON value, enforcing content type and body size. Request errors are *Error values with a safe public message and internal cause.
Types ¶
type DecodeOptions ¶
type Error ¶
type Error struct {
Status int `json:"-"`
Code string `json:"code"`
Message string `json:"message"`
Fields map[string]string `json:"fields,omitempty"`
// contains filtered or unexported fields
}
Error describes a public HTTP error. Its status and internal cause are not serialized, and domain errors need not import this package.
type ErrorMapper ¶
ErrorMapper is the contract used by HTTP consumers. Implementations map application errors and write their public response without exposing causes.
type HandlerAdapter ¶ added in v0.1.3
type HandlerAdapter struct {
// contains filtered or unexported fields
}
HandlerAdapter maps returned errors and logs failures at the net/http boundary. Wrap returns an ordinary HandlerFunc, composable with native middleware.
func NewHandlerAdapter ¶ added in v0.1.3
func NewHandlerAdapter(mapper ErrorMapper, logger logging.Logger) *HandlerAdapter
func (*HandlerAdapter) Wrap ¶ added in v0.1.3
func (a *HandlerAdapter) Wrap(handler func(stdhttp.ResponseWriter, *stdhttp.Request) error) stdhttp.HandlerFunc
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}