Documentation
¶
Overview ¶
Package gomod seeds a scaffold's go.mod with the direct requirements the generator's own import lines imply, and nothing more (spec 0200).
go mod tidy stays the owner of the file: the seed adds a missing require line at a known version, drops a line of its own whose import has gone, raises a line below a floor GTB declares, and leaves everything else, including the version of any other present line, exactly as it found it. It is pure over bytes so it is tested on literal go.mod text.
Index ¶
Constants ¶
const Latest = "latest"
Latest is the version of a requirement nothing knows a version for. Seed writes no line for it: tidy resolves it, which is what would have happened anyway, and a floor of "latest" is no floor.
Variables ¶
var Floors = map[string]string{}
Floors is the compatibility baseline this gtb declares: the minimum version of a module a scaffold must hold to work with the framework this gtb generates for (D8). Edit it in the change that bumps the dependency it protects. A present line below its floor is raised on regenerate.
Functions ¶
This section is empty.
Types ¶
type MapSource ¶
MapSource is a VersionSource over a map, for tests and for callers that already hold the answer.
type Option ¶
type Option func(*options)
Option adjusts Seed.
func Owned ¶
Owned names the modules the generator writes require lines for. A present line for one of them that is no longer wanted is dropped; a line for any other module is never dropped, whoever added it.
func WithModule ¶
WithModule sets the module path and go directive on a file that has none, which is how a fresh scaffold's go.mod comes to exist.
func WithoutTools ¶
WithoutTools drops the tool directives named, when present: the tools an older scaffold ran through go tool that are installed now (spec 0197 D12).
type Raise ¶
type Raise struct {
Path, From, To string
}
Raise records a present line moved up to a declared floor.
type Report ¶
type Report struct {
Added []string
Dropped []string
Raised []Raise
// DroppedTools names the tool directives removed because the tool is
// installed now rather than run through go tool (#86).
DroppedTools []string
// Unpinned names the wanted modules that had no version to seed; tidy
// resolves them.
Unpinned []string
}
Report says what Seed did, so the run can say it too.
type Requirement ¶
type Requirement struct {
Path string
Version string
// Floor marks a version GTB declares as its compatibility baseline (D8):
// a present line below it is raised. Without it a present line is never
// touched.
Floor bool
}
Requirement is one direct requirement the generator's output implies.
func LockstepFloors ¶
func LockstepFloors(reqs []Requirement, owned []string) []Requirement
LockstepFloors marks each owned requirement with a known version as a floor (spec 0200 D9, #87): the adapters implement the framework's interfaces and gtb links every one, so the version it was built against is the least a scaffold generated by it can hold. A requirement nothing knows a version for, and a module the generator does not own, are returned as they came.
func Requirements ¶
func Requirements(paths []string, src VersionSource, floors map[string]string) []Requirement
Requirements resolves the version of each wanted module in D4's order: a declared floor, else the source's answer, else Latest.
type VersionSource ¶
VersionSource answers which version of a module the generating binary knows, if any.
func BuildInfoSource ¶
func BuildInfoSource() VersionSource
BuildInfoSource reads the running binary's build info: gtb links every adapter, so the version it was built and tested against is the one to seed (D4). A binary built without module information answers nothing.