Documentation
¶
Overview ¶
Package frameworkmod reads what an application's go.mod declares about the Gombit framework module: the required version, the replace directive that applies to it, and so the framework release it names (Release). It is the one reading behind every command that reports the framework an app builds against (gombit contract app, gombit upgrade): they share which replace applies and which version, if any, is a framework release.
It reads go.mod alone, offline: it does not load the module graph, and knows nothing of a go.work (whether one applies is the go command's answer, `go env GOWORK`; see package upgrade). Within go.mod it picks the replace directive the go command applies, and refuses what the go command refuses: the framework required twice, or replaced twice with different targets.
Index ¶
Constants ¶
const ModulePath = "github.com/gombit-dev/gombit"
ModulePath is the module a Gombit application requires.
Variables ¶
var ErrNotRequired = errors.New("go.mod does not require " + ModulePath)
ErrNotRequired: go.mod does not require the framework module.
Functions ¶
This section is empty.
Types ¶
type Declaration ¶
type Declaration struct {
// Required is the require directive's version.
Required string
// Replace is the replace directive that applies to Required, or nil.
Replace *Replacement
// Replaces is every replace of the framework module in go.mod, applying
// or not, in file order (an exact repeat counted once). Planning a move
// of the require needs them all: a replace of the target version, or one
// of every version an exact replace shadows today, decides the build
// after the move (Resolve).
Replaces []Replacement
}
Declaration is what go.mod declares about the framework module.
func Parse ¶
func Parse(path string, data []byte) (Declaration, error)
Parse reads go.mod content (path names it in errors).
func Read ¶
func Read(workDir string) (Declaration, error)
Read reads the go.mod in workDir. A missing file is reported as an error wrapping os.ErrNotExist; a go.mod not requiring the framework, as ErrNotRequired.
func (Declaration) Release ¶
func (d Declaration) Release() string
Release is the framework release go.mod names: the required version, or the version of a replace by the framework module itself. It is empty when the framework is replaced by a local directory or by another module (a fork): neither is a release of the framework, whatever its version says.
type Replacement ¶
type Replacement struct {
// Path is a module path, or a local directory when Version is empty.
Path string `json:"path"`
// Version is the replacement module's version; empty for a directory.
Version string `json:"version,omitempty"`
// ForVersion is the framework version the replace applies to (its left
// side's version), or empty when it applies to every version. A replace
// of every version keeps pinning the build when the require moves; one of
// the required version stops applying.
ForVersion string `json:"for_version,omitempty"`
}
Replacement is a replace directive's target.
func Resolve ¶
func Resolve(replaces []Replacement, version string) *Replacement
Resolve is the replacement in replaces that applies to the framework at version, as the go command resolves it: a replace of that exact version wins over one of every version, and a replace of another version does not apply. Nil when none applies. A planner that edits the set (moves the require, drops a replace) resolves again with it.
func (Replacement) Local ¶
func (r Replacement) Local() bool
Local reports whether the replacement is a local directory.
func (Replacement) String ¶
func (r Replacement) String() string
String is the replacement as go.mod writes it: "path version", or the directory.