Metago documentation

Getting started

Metago runs alongside the Go compiler. You describe code generation with source comments and reusable Go templates; Metago emits ordinary Go.

Metago is early-stage software. APIs and directives may evolve.

Install

go install github.com/guillemus/metago@latest

Optionally install the Metago skill for supported coding agents:

npx skills add guillemus/metago --skill metago

Your first generator

Create stringer.metago anywhere beneath the directory you plan to scan:

{{ define "stringer" }}
func (v {{ name . }}) String() string {
    switch v {
    {{- range .Values }}
    case {{ .Name }}:
        return {{ quote .Name }}
    {{- end }}
    default:
        return "unknown"
    }
}
{{ end }}

Annotate a Go type:

package example

//mgo:gen stringer
type Status int

const (
    StatusPending Status = iota
    StatusRunning
    StatusDone
)

Run Metago from the scan root:

metago .

Metago creates a package-level meta.go containing the generated String method.

CLI

metago              # scan the current directory recursively
metago ./path       # scan another root
metago -v           # show verbose logs
metago --verbose

Templates may live anywhere under the scan root. Metago skips hidden directories, vendor, and testdata. It ignores _test.go, meta.go, and *_meta.go while scanning packages. Template names must be unique across the root.