Help us shape the future of Go! Take the 2026 Go Developer Survey

codegen

package
v0.263.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package codegen renders a complete consumer `main.go` from a KDL Guardfile, so a consumer never hand-writes the specverb wiring. See docs/specverb.md.

Index

Constants

View Source
const (
	TransportSpec = "spec"
	TransportExec = "exec"
	TransportMCP  = "mcp"
)

Transport is the dialect one merged member speaks: spec (HTTP/specverb), exec (wrapped binary/execverb), or mcp (upstream MCP server/mcpverb).

Variables

This section is empty.

Functions

func Render

func Render(gf *guardfile.Guardfile, guardfileName string) ([]byte, error)

Render emits a gofmt'd `package main` wiring specverb.Mount for gf, the single-guardfile convenience over RenderSet.

func RenderParams

func RenderParams(sp SetParams) ([]byte, error)

RenderParams emits a gofmt'd `package main` from pre-planned SetParams, mixing spec and exec members onto the one shared binary. The driver's entry.

func RenderSet

func RenderSet(gfs []*guardfile.Guardfile, names []string) ([]byte, error)

RenderSet emits a gofmt'd `package main` mounting every spec guardfile onto one binary. names are the embed filenames, parallel to gfs. Spec-only.

Types

type EmbeddedFile

type EmbeddedFile struct {
	Source string
	Name   string
}

EmbeddedFile maps the guardfile-relative source key used by execverb to the project-relative artifact name embedded in generated Go.

type Params

type Params struct {
	Transport     string // TransportSpec | TransportExec
	Binary        string // binary name, e.g. ward (Guardfile group[0])
	GuardfileName string // embedded Guardfile filename, e.g. forgejo.guardfile.kdl
	SpecLockName  string // committed gzip lock filename, e.g. forgejo.swagger.lock.json.gz
	SpecURL       string // upstream Swagger URL; the `umbra lock` source and bootstrap fallback
	SpecEnvVar    string // env var overriding the embedded lock, e.g. WARD_KDL_SPEC

	// Providers are the value-source provider names this member's guardfile uses,
	// so the codegen wires exactly the resolvers in play. Empty for an exec member.
	Providers []string

	// ProviderDecls are the member's `provider <name> { exec ... }` declarations,
	// the consumer-supplied resolvers for any non-builtin provider it names.
	ProviderDecls []guardfile.ProviderDecl

	// EmbeddedFiles are fixed build-time sources used as typed argv by an exec
	// member. Empty for spec members.
	EmbeddedFiles []EmbeddedFile

	// Replace marks an exec member that declares `replace`: the generated binary
	// is the wrapped tool rather than a verb group under a driver.
	Replace bool

	// Occluded is the binary name a replacement is installed under. Empty unless
	// Replace is set. See docs/execverb-replacement.md.
	Occluded string
}

Params is the per-consumer data the template binds to, derived from the Guardfile. The spec-lock fields are empty for an exec member. See specverb.md.

func Plan

func Plan(gf *guardfile.Guardfile, guardfileName string) (Params, error)

Plan derives the per-consumer Params from gf without rendering, the shared derivation behind both Render and the driver. guardfileName feeds the embed.

func PlanExec

func PlanExec(group, providers []string, guardfileName string, decls []guardfile.ProviderDecl) (Params, error)

PlanExec derives an exec member's Params from its wrap group and the provider names its env injections use; no upstream spec. See umbra-cli.md.

func PlanMCP

func PlanMCP(group, providers []string, guardfileName string, decls []guardfile.ProviderDecl) (Params, error)

PlanMCP derives an mcp member's Params from its wrap group and the provider names its transport uses. No SpecURL: `mcp <transport>` already says where.

type SetParams

type SetParams struct {
	Binary    string
	Mounts    []Params
	HasSpec   bool
	HasExec   bool
	HasMCP    bool
	HasEmbeds bool
	// ExecProviders are the consumer-declared resolvers actually named by some
	// member, deduped. umbra itself ships none. See docs/value-providers.md.
	ExecProviders []guardfile.ProviderDecl

	// Replace roots the binary at the wrapped tool, so a grant is a top-level
	// verb. Only ever set with exactly one mount.
	Replace bool

	// Occluded is the tool name the replacement stands in front of.
	Occluded string
}

SetParams binds the merged-binary template: one shared Binary and N mounts. HasSpec/HasExec/HasMCP gate the per-transport imports the template emits.

func PlanSet

func PlanSet(gfs []*guardfile.Guardfile, names []string) (SetParams, error)

PlanSet derives the merged params for guardfiles that share a binary name. It fails closed on an empty set or a Group[0] disagreement (one binary per merge).

Jump to

Keyboard shortcuts

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