mymods

package
v0.0.0-...-b13924d Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: MIT Imports: 11 Imported by: 0

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

func ReadTable() (Table, error)

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

func (t Table) Dependencies() map[string]*Module

Dependencies returns a map from dependent module paths to descriptions of each dependent module.

func (Table) MainModule

func (t Table) MainModule() *Module

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

func (t Table) MainPackage() string

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

Jump to

Keyboard shortcuts

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