Documentation
¶
Overview ¶
Package fileasm assembles a complete generated Go source file — the DO-NOT-EDIT header, the build constraint, the package clause, the import block, and the rendered body — through a single template. It is shared by every emitter so file scaffolding is produced one way, in one place.
The assembler is deliberately parameterised rather than opinionated: the caller supplies the exact header text, build tag, and the already-grouped import lines. This lets each emitter keep its own byte-for-byte output (the raw purego files, the CGo library files, and the idiomatic files use different header strings and import groupings) while still flowing through one template. gofmt canonicalises whitespace afterwards, so only tokens matter.
SCOPE — shared: used by every emitter (raw and idiomatic, frameworks and libraries) so file scaffolding is produced one way, in one place.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assemble ¶
Assemble renders a complete generated file from f. The result is pre-gofmt; the caller is expected to run it through go/format.
func ImportLinesStdlibExternalInternal ¶
ImportLinesStdlibExternalInternal renders import entries for the alias→path map in three groups — standard library, third-party external, then this module's own (github.com/deploymenttheory/…) packages — each separated by a blank line, paths sorted within a group. An alias is rendered only when it differs from the path's last segment. This is the grouping the raw emitters use (distinct from the two-group goimports grouping).
func ImportLinesStdlibMod ¶
ImportLinesStdlibMod renders import entries for the alias→path map, split into the two goimports groups goimports itself produces — standard-library packages first, then everything else (third-party and same-module) — separated by a blank line. Within each group entries are sorted by path then alias (the same path can be imported under two aliases). The blank-line entry survives gofmt as the canonical group separator.
func IsStdlibImport ¶
IsStdlibImport reports whether an import path names a standard-library package. Standard-library paths have no dot in their first segment (e.g. "context", "unsafe", "go/token"); module paths begin with a domain such as "github.com".
Types ¶
type File ¶
type File struct {
// Header is the DO-NOT-EDIT comment block (no trailing newline).
Header string
// BuildTag is the build constraint line, e.g. "//go:build darwin" (no
// trailing newline); empty to omit.
BuildTag string
// PkgName is the Go package name.
PkgName string
// ImportLines are the rendered import entries (each `"path"` or
// `alias "path"`, with blank-line group separators already inserted). Empty
// to omit the import block entirely.
ImportLines []string
// Body is the already-rendered file body (declarations).
Body string
}
File is the data for the file scaffold template.