contract

command
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Contract example

Demonstrates Huma DTOs, D10 validation errors, success meta, §41 category errors (not_found), /openapi.json, and the /docs try-it-out UI on framework.App.API().

Run

go run ./examples/contract

Open http://127.0.0.1:8080/docs for Swagger UI. Try-it-out calls this same process. Raw Gin routes are not listed there.

curl -sS http://127.0.0.1:8080/openapi.json
go run ./cmd/gombit openapi generate \
  --url http://127.0.0.1:8080/openapi.json \
  --out /tmp/gombit-openapi.json

List (data + page meta)

curl -sS http://127.0.0.1:8080/api/v1/widgets

Get existing / missing

curl -sS http://127.0.0.1:8080/api/v1/widgets/widget-1
curl -sS http://127.0.0.1:8080/api/v1/widgets/missing

Missing id returns:

{
  "error": {
    "code": "not_found",
    "message": "widget not found",
    "request_id": "..."
  }
}

Valid create

curl -sS -X POST http://127.0.0.1:8080/api/v1/widgets \
  -H 'Content-Type: application/json' \
  -d '{"name":"Second widget","color":"green"}'

Invalid body (D10 field errors)

curl -sS -X POST http://127.0.0.1:8080/api/v1/widgets \
  -H 'Content-Type: application/json' \
  -d '{}'

See docs/contract.md and docs/openapi.md.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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