-
Release v0.10.0 Stable
released this
2026-03-25 16:58:33 -06:00 | 0 commits to main since this releasev0.10.0
code.nochebuena.dev/go/httputilOverview
httputilremoves HTTP boilerplate from business logic. Generic adapter functions wrap
pure Go functions intohttp.HandlerFuncvalues, handling JSON decode, struct validation,
JSON encode, and error-to-HTTP-status mapping automatically. A singleErrorhelper
translates any*xerrors.Errto the correct HTTP status and JSON body.What's New in v0.10.0
platformCodein error responsesError(w, err)now includes"platformCode"in the JSON body when the*xerrors.Err
carries one (viaWithPlatformCode). Omitted when not set.{ "code": "NOT_FOUND", "platformCode": "EMPLOYEE_NOT_FOUND", "message": "employee not found" }This pairs with
xerrorsv0.10.0 which introducedWithPlatformCode. The transport
layer (httputil) passes it through transparently — no mapping or logic added here.Backwards-compatible: error responses for errors without a platform code are
identical to v0.9.0.What's Included
Handler adapters (generic):
Handle[Req, Res any](v Validator, fn func(ctx, Req) (Res, error)) http.HandlerFuncHandleNoBody[Res any](fn func(ctx) (Res, error)) http.HandlerFuncHandleEmpty[Req any](v Validator, fn func(ctx, 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 (updated)
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@v0.10.0Changelog
See CHANGELOG.md.
Downloads