Documentation
¶
Overview ¶
Package scaffold renders the `nucleus new` starter project from a tree of embedded template files instead of inline Go string literals.
Templates live under templates/ in two layers:
- templates/_common/ — files shared by every starter template.
- templates/<name>/ — files specific to one template (api, mvc, suite).
The path of a template file UNDER its layer directory mirrors its path in the generated project. A template layer may carry a file the _common layer also has (the suite's README is not the empty skeleton's): the template's copy wins, and the project gets one file at that path. Go source files carry a ".go.tmpl" suffix (and other rendered files a ".tmpl" suffix) so the Go toolchain ignores them in this module; the suffix is stripped on render. Files with a real extension and no ".tmpl" suffix (e.g. .gitignore, home.html, *.sql, *.csv) are copied verbatim and never run through text/template, so literal "{{ ... }}" sequences (such as the HTML home page) survive intact.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
File is a single rendered output: a slash-separated path relative to the project root and the rendered body. Callers convert RelPath to an OS path.
func Render ¶
func Render(tmpl string, data TemplateData) ([]File, error)
Render walks templates/_common then templates/<tmpl>, executing every ".tmpl" file through text/template and copying every other file verbatim. The returned files use slash-separated, project-relative paths with the ".tmpl" suffix stripped. The _common layer is emitted before the template-specific layer so callers preserve a deterministic order.
type TemplateData ¶
type TemplateData struct {
Module string
ProjectName string
Port int
FrameworkVersion string
// Template is the starter template the project was rendered from
// ("api", "mvc", "suite"). A file in the _common layer reads it when
// one line differs per template and duplicating the whole file into
// each layer would be worse: the Dockerfile copies rbac_policy.csv,
// which only the templates that scaffold one have.
Template string
// GoVersion is the `go` directive written into the generated go.mod
// (e.g. "1.26.4"). Toolchain is the `toolchain` directive ("" omits the
// line, the current state). Both track the framework's own go.mod; see
// resolveGoDirectives in internal/cli/new.go (enforced by
// TestScaffoldGoDirectivesTrackGoMod).
GoVersion string
Toolchain string
// Database is the engine name the project starts on ("sqlite",
// "postgres", …), DatabaseURL the databases.default.url written into
// nucleus.yml, and DriverModule the driver module main.go imports for
// it. See scaffoldDatabases in internal/cli/new.go.
Database string
DatabaseURL string
DriverModule string
// QuarkDriver is the database/sql driver name the Quark ORM opens the
// same engine with, QuarkDSN the data source it takes (a file for
// sqlite, a URL or DSN for the servers) and QuarkDriverModule the
// Quark driver module that registers the engine's error classifier.
// Only the suite template and `--with quark` read them.
QuarkDriver string
QuarkDSN string
QuarkDriverModule string
// With lists the suite modules the project was scaffolded with (the
// names `--with` accepts: orbit, quark, quarkbridge, quarkdatasource),
// in catalogue order. Templates branch on it through Has.
With []string
}
TemplateData carries the values interpolated into rendered templates via the placeholders {{.Module}}, {{.ProjectName}}, {{.Port}}, {{.FrameworkVersion}}, {{.GoVersion}}, {{.Toolchain}}, {{.Database}}, {{.DatabaseURL}}, {{.DriverModule}}, {{.QuarkDriver}}, {{.QuarkDSN}}, {{.QuarkDriverModule}}, {{.Template}} and the {{.With}} list a template asks about with {{if .Has "orbit"}}.
func (TemplateData) Has ¶
func (d TemplateData) Has(name string) bool
Has reports whether the project was scaffolded with the named suite module, for template conditionals such as {{if .Has "orbit"}}.