-
Release v1.0.0 Stable
released this
2026-05-12 11:38:44 -06:00 | 0 commits to main since this releasev1.0.0
code.nochebuena.dev/go/httputilOverview
httputilremoves HTTP boilerplate from business logic. Generic adapter functions
(Handle,HandleNoBody,HandleEmpty) wrap pure Go functions into
http.HandlerFuncvalues, handling JSON decode, struct validation, JSON encode,
and error-to-HTTP-status mapping automatically.v1.0.0 commits the full API as stable and bumps all micro-lib dependencies to their
v1 releases (xerrors v1.0.1,valid v1.0.1).What Changed Since v0.10.0
- Dependency
xerrorsbumped fromv0.10.0tov1.0.1 - Dependency
validbumped fromv0.9.0tov1.0.1 - Go directive bumped from
1.25to1.26 - API unchanged — all adapters and helpers from v0.10.0 are stable
What's Included
Handler adapters (generic):
Handle[Req, Res any](v Validator, fn func(ctx context.Context, req Req) (Res, error)) http.HandlerFuncHandleNoBody[Res any](fn func(ctx context.Context) (Res, error)) http.HandlerFuncHandleEmpty[Req any](v Validator, fn func(ctx context.Context, req Req) error) http.HandlerFunc
Manual handler type:
HandlerFunc func(w, r) error— implementshttp.Handler
Response helpers:
JSON(w, status, v)— encodes v as JSON, sets Content-Type: application/jsonNoContent(w)— writes 204 No ContentError(w, err)— maps*xerrors.Errto HTTP status; includesplatformCodewhen present
xerrors.Code→ HTTP status mapping (12 codes):Code Status ErrInvalidInput400 Bad Request ErrUnauthorized401 Unauthorized ErrPermissionDenied403 Forbidden ErrNotFound404 Not Found ErrAlreadyExists409 Conflict ErrGone410 Gone ErrPreconditionFailed412 Precondition Failed ErrRateLimited429 Too Many Requests ErrInternal500 Internal Server Error ErrNotImplemented501 Not Implemented ErrUnavailable503 Service Unavailable ErrDeadlineExceeded504 Gateway Timeout Installation
go get code.nochebuena.dev/go/httputil@v1.0.0Changelog
See CHANGELOG.md.
Downloads
- Dependency