adapters-chi

command
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package adapters-chi demonstrates the three-layer codec pipeline pattern using the chi router. The architecture mirrors adapters-nethttp exactly — the only difference is the HTTP router and how path variables are extracted.

Three boundary codecs:

Codec[CreateUserReq] — HTTP request contract (what the client sends) Codec[UserRecord] — database contract (the SQL model) Codec[User] — HTTP response contract (what the client receives)

Two pure domain functions connect them (Layer 2):

buildUserRecord(CreateUserReq) UserRecord — request → DB record buildUserResponse(UserRecord) User — DB record → response

Routes:

  • POST /users — body validate, response headers + cookies (codec-validated), content negotiation
  • GET /users/{id} — UUID path param, BuildPath type-safe URL construction
  • GET /users — query params (page, search)
  • GET /profile — request-side cookie + header validation

A CountingObserver wired into every route collects per-request metrics and per-field validation errors without any metrics library dependency.

Run with: go run ./examples/adapters-chi

Jump to

Keyboard shortcuts

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