Documentation ¶
Overview ¶
Package mymods gives a Go program access to the module version metadata placed into its own executable image by the Go toolchain.
This allows, for example, a program to discover what version of its main module was used to build it, which it might then choose to return as its own version in response to a run with a --version or similar option.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct { Path string Version VersionStr }
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func ReadTable ¶
ReadTable reads the module information table from the current executable.
An error is returned if the current executable cannot be read, if it lacks a module information table, if the table is invalid, etc.
Note that the same caveats that apply to os.Executable also apply here: the executable that started the program is not necessarily the same executable running now, the executable may no longer be present, etc.
func (Table) Dependencies ¶
Dependencies returns a map from dependent module paths to descriptions of each dependent module.
func (Table) MainModule ¶
MainModule returns the path of the main module that the executable was built from. This is the module that contained the package path returned by MainPackage.
Full version information is not always available for the main module. The version for MainModule might be DevelVersion, indicating that the build was made in a context where version information could not be determined.
The result is nil if main module information is not present in the module information table.
func (Table) MainPackage ¶
MainPackage returns the path of the main package that the executable was built from. This is the full path to the package containing func main, as opposed to the module that contained it.
An empty string is returned if main package information is not available.
type VersionStr ¶
type VersionStr string
const DevelVersion VersionStr = "(devel)"
func (VersionStr) String ¶
func (s VersionStr) String() string