The Go runtime module#
Generated Go is not self-contained. The support types it leans on live in one
module, gitlab.com/terryp/model/go-runtime, and every generated file imports
it. Add it to the module that holds the generated file:
go get gitlab.com/terryp/model/go-runtime
Generation itself needs the dependency in place: a model with routes type-checks the target package between passes, and that fails if the import cannot be resolved.
Why a module rather than a copy#
The support types used to be copied into each generated file. That made a
small output mostly scaffolding, and it made two generated packages in one
program unable to talk to each other — each had its own Optional[T] and its
own ValidationError, distinct types as far as Go was concerned. Sharing one
module fixes both.
What you use#
The generator imports each package under a fixed alias, so generated declarations read the way this table spells them.
Import path |
Alias |
What it holds |
|---|---|---|
|
|
|
|
|
|
|
|
|
An optional field is mdl.Optional[T]; read it with IsSome, Get, or
GetOrZero, and build one with mdl.Some or mdl.None[T](). A Validate
method reports *mdl.ValidationError. A route’s error response type
implements mdl.FromError, and either it or the error implements
mdl.StatusCoder.
What you do not#
Everything under …/go-runtime/gen is a generator implementation detail:
the validation walk, the yaml and etree helpers, the pgx converters, the REST
handlers. Those identifiers are exported only because generated code sits in
your package and cannot reach unexported ones. They carry no compatibility
promise and may change in any release. Nothing outside generated code should
name them.
Dependencies#
Only the root package is unconditional, and it pulls in nothing third-party.
The feature packages are separate so a consumer who enables no features never
compiles fyne or pgx: yamlx needs gopkg.in/yaml.v3, xmlx needs
github.com/beevik/etree, fyne needs fyne.io/fyne/v2, and pg, pgconv
and rest need github.com/jackc/pgx/v5. Go only builds the ones your
generated file actually imports.