Bump xerrors to v1.0.1 and valid to v1.0.1. Go directive bumped to 1.26. API committed as stable: Handle, HandleNoBody, HandleEmpty, HandlerFunc, JSON, NoContent, and Error are unchanged from v0.10.0.
3.7 KiB
3.7 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
1.0.0 - 2026-05-12
Changed
- Go directive bumped from 1.25 to 1.26
xerrorsdependency bumped to v1.0.1validdependency bumped to v1.0.1
Stabilization
- API committed as stable.
Handle,HandleNoBody,HandleEmpty,HandlerFunc,JSON,NoContent, andErrorare unchanged from v0.10.0.
0.10.0 - 2026-03-25
Changed
Error(w http.ResponseWriter, err error)— now includes"platformCode"in the JSON error body when the*xerrors.Errcarries one; omitted otherwise- Upgraded
code.nochebuena.dev/go/xerrorsdependency tov0.10.0
Design Notes
platformCodeis the domain-layer error identifier introduced inxerrorsv0.10.0. It travels throughErrortransparently — no transport-layer logic depends on it.- Backwards-compatible: error responses without a platform code are identical to v0.9.0.
0.9.0 - 2026-03-18
Added
Handle[Req, Res any](v valid.Validator, fn func(ctx context.Context, req Req) (Res, error)) http.HandlerFunc— decodes the JSON request body intoReq, validates it with the injectedValidator, callsfn, and encodes the result as JSON with HTTP 200; invalid JSON returns 400HandleNoBody[Res any](fn func(ctx context.Context) (Res, error)) http.HandlerFunc— no body decode or validation; callsfnand encodes the result as JSON with HTTP 200; intended for GET and DELETE endpointsHandleEmpty[Req any](v valid.Validator, fn func(ctx context.Context, req Req) error) http.HandlerFunc— decodes and validates the JSON request body, callsfn, returns HTTP 204 on success; intended for write endpoints with no response bodyHandlerFunctype —func(w http.ResponseWriter, r *http.Request) error; implementshttp.Handler; on non-nil return, routes the error throughError(w, err)for automatic status mappingJSON(w http.ResponseWriter, status int, v any)— encodesvas JSON and writes it with the given status code; setsContent-Type: application/jsonNoContent(w http.ResponseWriter)— writes HTTP 204 No ContentError(w http.ResponseWriter, err error)— maps*xerrors.Errcodes to HTTP status codes and writes a{"code": "...", "message": "..."}JSON body; includes any extra fields from the error; falls back to 500 for unknown errorsxerrors.Codeto HTTP status mapping (12 codes):ErrInvalidInput→ 400,ErrUnauthorized→ 401,ErrPermissionDenied→ 403,ErrNotFound→ 404,ErrAlreadyExists→ 409,ErrGone→ 410,ErrPreconditionFailed→ 412,ErrRateLimited→ 429,ErrInternal→ 500,ErrNotImplemented→ 501,ErrUnavailable→ 503,ErrDeadlineExceeded→ 504
Design Notes
- Business functions wrapped by
Handle,HandleNoBody, andHandleEmptyhave nohttp.ResponseWriteror*http.Requestin their signatures, making them callable directly in unit tests withcontext.Background()and a typed request value. Erroris the single translation point fromxerrors.Codeto HTTP status; all handler adapters route through it, preventing fragmented status code contracts across the codebase.- Validation is injected via
valid.Validatorand runs before the business function is called; an invalid request never reaches business logic.