Documentation
¶
Overview ¶
Package gomod provides a parser for go.mod files according to the official specification. Since this package heavily relies on the `go` command, a go installation is required for this module to work.
mod, err := gomod.NewFromDir("./testdata/default/")
if err != nil {
return
}
fmt.Println("Module path:", mod.Module.Path)
fmt.Println("Go version:", mod.Go)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exclude ¶
type Exclude struct {
// The path of the module to be excluded.
Path string `json:"Path"`
// The version of the module to be excluded.
Version string `json:"Version"`
}
An exclude directive prevents a module version from being loaded by the go command. See https://go.dev/ref/mod#go-mod-file-exclude
type GoMod ¶
type GoMod struct {
// A module directive defines the main module’s path.
Module Module `json:"Module"`
// A go directive indicates that a module was written assuming the semantics of a given version of Go.
Go string `json:"Go"`
// A toolchain directive declares a suggested Go toolchain to use with a module.
Toolchain string `json:"Toolchain"`
// A require directive declares a minimum required version of a given module dependency.
Require []Require `json:"Require"`
// An exclude directive prevents a module version from being loaded by the go command.
Exclude []Exclude `json:"Exclude"`
// A replace directive replaces the contents of a specific version of a module, or all versions of a module, with contents found elsewhere.
Replace []Replace `json:"Replace"`
// A retract directive indicates that a version or range of versions of the module should not be depended upon.
Retract []Rectract `json:"Retract"`
}
A module is defined by a file named go.mod in its root directory. See https://go.dev/ref/mod#go-mod-file
func NewFromDir ¶
NewFromDir parses and returns the go.mod file located in the directory d.
type Module ¶
type Module struct {
// The main module’s path.
Path string `json:"Path"`
}
A module directive defines the main module’s path. See https://go.dev/ref/mod#go-mod-file-module
type New ¶
type New struct {
// The path of the module.
Path string `json:"Path"`
// If the path is not a local path, it must be a valid module path. In this case, a version is required.
Version string `json:"Version"`
}
The module replacement.
type Old ¶
type Old struct {
// The path of the module.
Path string `json:"Path"`
// If a version is present only that specific version of the module is replaced.
Version string `json:"Version"`
}
The module to be replaced.
type Rectract ¶
type Rectract struct {
// A directive may be written with either a single version or with a closed interval of versions with an upper and lower bound.
Low string `json:"Low"`
// A directive may be written with either a single version or with a closed interval of versions with an upper and lower bound.
High string `json:"High"`
// A directive should have a comment explaining the rationale for the retraction.
Rationale string `json:"Rationale"`
}
A retract directive indicates that a version or range of versions of the module should not be depended upon. See https://go.dev/ref/mod#go-mod-file-retract
type Replace ¶
type Replace struct {
// The module to be replaced.
Old Old `json:"Old"`
// The module replacement.
New New `json:"New"`
}
A replace directive replaces the contents of a specific version of a module, or all versions of a module, with contents found elsewhere. See https://go.dev/ref/mod#go-mod-file-replace
type Require ¶
type Require struct {
// The path of the module dependency.
Path string `json:"Path"`
// The minimum required version of the module dependency.
Version string `json:"Version"`
// Indicates that no package from the required module is directly imported.
Indirect bool `json:"Indirect"`
}
A require directive declares a minimum required version of a given module dependency. See https://go.dev/ref/mod#go-mod-file-require