Skip to content

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.

ExhibitWhat it shows
simpleA single command with one flag and one positional argument
nestedA two-level command tree (parent + two subcommands)
all-markersEvery +glacier: marker valid on a command struct in one place

mock

Generates typed mock implementations from +glacier:mock annotated interfaces.

ExhibitWhat it shows
interface-onlyA single interface with two methods
nested-interfacesAn interface that embeds another interface
with-types-from-other-packageMethods whose signatures reference types from an imported package

httpmock

Generates httpmock handler scaffolding from +glacier:mock annotated HTTP interfaces.

ExhibitWhat it shows
programmable-routerA router with multiple routes registered at test setup
recording-disabledRecording mode turned off; all unmatched requests fail immediately
with-body-closureA handler that uses a body closure to generate response bodies per call

How to read an exhibit

Each exhibit page shows:

  1. The input source (in.go) with its +glacier: markers.
  2. The expected generated output (out.go).
  3. 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.

Apache-2.0