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

gomod

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

View Source
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

type MapSource map[string]string

MapSource is a VersionSource over a map, for tests and for callers that already hold the answer.

func (MapSource) Version

func (m MapSource) Version(path string) (string, bool)

Version implements VersionSource.

type Option

type Option func(*options)

Option adjusts Seed.

func Owned

func Owned(paths ...string) Option

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

func WithModule(path, goVersion string) Option

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 WithTools

func WithTools(paths ...string) Option

WithTools adds tool directives that are missing.

func WithoutTools

func WithoutTools(paths ...string) Option

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 Replace

type Replace struct {
	Path string
	Dir  string
}

Replace is the development replace directive GTB_FRAMEWORK_REPLACE asks for.

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.

func Seed

func Seed(src []byte, want []Requirement, replace *Replace, opts ...Option) ([]byte, Report, error)

Seed edits src, a go.mod (nil for a new file), so that every wanted requirement has a line, every owned line nothing wants any more is gone, and the development replace is present or absent as asked. Everything else in the file is left as it was.

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

type VersionSource interface {
	Version(path string) (string, bool)
}

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.

Jump to

Keyboard shortcuts

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