Codegen Gallery
Nine annotated examples cover the three Glacier code generators. Each exhibit is a self-contained pair: in.go (annotated source) and out.go (expected generated file). CI runs each generator over its in.go and asserts byte-equality with out.go; drift fails the build.
Source lives under docs/examples/codegen/.
cli (cligen)
Generates the command-wiring file zz_generated_cli.go from +glacier:command annotated structs.
| Exhibit | What it shows |
|---|---|
| simple | A single command with one flag and one positional argument |
| nested | A two-level command tree (parent + two subcommands) |
| all-markers | Every +glacier: marker valid on a command struct in one place |
mock
Generates typed mock implementations from +glacier:mock annotated interfaces.
| Exhibit | What it shows |
|---|---|
| interface-only | A single interface with two methods |
| nested-interfaces | An interface that embeds another interface |
| with-types-from-other-package | Methods whose signatures reference types from an imported package |
httpmock
Generates httpmock handler scaffolding from +glacier:mock annotated HTTP interfaces.
| Exhibit | What it shows |
|---|---|
| programmable-router | A router with multiple routes registered at test setup |
| recording-disabled | Recording mode turned off; all unmatched requests fail immediately |
| with-body-closure | A handler that uses a body closure to generate response bodies per call |
How to read an exhibit
Each exhibit page shows:
- The input source (
in.go) with its+glacier:markers. - The expected generated output (
out.go). - A short explanation of what the generator did and why.
To reproduce any exhibit locally:
sh
cd docs/examples/codegen/<exhibit>
glacier generate ./...The generated file should be byte-for-byte identical to out.go.