goinfo

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 11 Imported by: 6

Documentation

Index

Constants

View Source
const (
	GO_MAJOR_1    = 1
	GO_VERSION_16 = 16 // unsupported
	GO_VERSION_17 = 17
	GO_VERSION_18 = 18
	GO_VERSION_19 = 19
	GO_VERSION_20 = 20
	GO_VERSION_21 = 21
	GO_VERSION_22 = 22
	GO_VERSION_23 = 23
	GO_VERSION_24 = 24
	GO_VERSION_25 = 25
)

Variables

View Source
var ErrGoModDoesNotHaveModule = errors.New("go.mod does not have module")
View Source
var ErrGoModNotFound = errors.New("go.mod not found")

Functions

func CmpInt added in v1.0.26

func CmpInt(x, y string) int

func CompareSemVer added in v1.0.26

func CompareSemVer(v, w string) int

func CompareVersion added in v1.0.26

func CompareVersion(x, y string) int

func FindGoModDir added in v1.0.37

func FindGoModDir(dir string) (string, error)

func FindGoModDirSubPath added in v1.0.45

func FindGoModDirSubPath(dir string) ([]string, string, error)

FindGoModDirSubPath find go.mod by traversing dir bottom up, upon finding a go.mod file, it returns the corresponding sub path and root dir

func FromToolchain added in v1.0.26

func FromToolchain(name string) string

func GetGoVersionOutput

func GetGoVersionOutput(goBinary string) (string, error)

func GetModPath added in v1.0.37

func GetModPath(dir string) (string, error)

func IsValidSemVer added in v1.0.26

func IsValidSemVer(v string) bool

func IsValidVersion added in v1.0.26

func IsValidVersion(x string) bool

func ListFiles added in v1.1.0

func ListFiles(dir string, args []string) ([]string, error)

ListFiles list all go files, return a list of absolute paths go list -e -json ./pkg

func ListPackagePaths added in v1.1.0

func ListPackagePaths(dir string, mod string, args []string) ([]string, error)

go list ./pkg

func ListRelativeFiles added in v1.0.51

func ListRelativeFiles(dir string, args []string) ([]string, error)

ListRelativeFiles list all go files, return a list of relative paths go list -e -json ./pkg

func ModCompare added in v1.0.26

func ModCompare(path string, x, y string) int

func PkgWithinModule added in v1.1.0

func PkgWithinModule(pkgPath string, module string) (suffix string, ok bool)

func ResolveMainModule added in v1.0.19

func ResolveMainModule(dir string) (subPaths []string, mainModule string, err error)

ResolveMainModule returns the main module path and subPaths to the directory containing the go.mod file from dir

func ResolveModulePkgPath added in v1.0.51

func ResolveModulePkgPath(dir string) (mainModPath string, pkgPath string, err error)

Types

type GoVersion

type GoVersion struct {
	Major int // 1
	Minor int // 17
	Patch int // 5

	OS   string
	Arch string
}

func GetGorootVersion added in v1.1.3

func GetGorootVersion(goroot string) (*GoVersion, error)

func ParseGoVersion

func ParseGoVersion(s string) (*GoVersion, error)

func ParseGoVersionNumber added in v1.0.37

func ParseGoVersionNumber(version string) (*GoVersion, error)

ParseGoVersionNumber parses example input: 1.23rc1

func (*GoVersion) String

func (c *GoVersion) String() string

type LoadPackageOptions added in v1.1.0

type LoadPackageOptions struct {
	Dir     string
	Mod     string
	ModFile string // -modfile flag
	Goroot  string // GOROOT env
	Deps    bool   // -deps flag
	Test    bool   // -test flag, if true, will have packages like "github.com/xhd2015/xgo/runtime/test/trap/inspect [github.com/xhd2015/xgo/runtime/test/trap/inspect.test]", so don't set it
}

type ModVersion added in v1.0.26

type ModVersion struct {
	Path    string
	Version string
}

type Package added in v1.1.0

type Package struct {
	// the abs dir
	Dir        string
	Name       string // the package name, e.g. "github.com/x/y/v2" -> y
	ImportPath string
	// the file names
	// e.g.: main.go, option.go
	GoFiles     []string
	TestGoFiles []string
	// XTestGoFiles is when a _test.go file
	// declares package as xxx_test, while the
	// package name of normal file is xxx
	XTestGoFiles []string

	Goroot   bool // is this package in the Go root?
	Standard bool // is this package part of the standard Go library?
	DepOnly  bool // package is only a dependency, not explicitly listed

	Incomplete bool          // this package or a dependency has an error
	Error      *PackageError // error loading package
}

check 'go help list'

func ListPackages added in v1.0.39

func ListPackages(args []string, opts LoadPackageOptions) ([]*Package, error)

go list -e -json ./pkg

type PackageError added in v1.1.0

type PackageError struct {
	ImportStack []string // shortest path from package named on command line to this one
	Pos         string   // position of error (if present, file:line:col)
	Err         string   // the error itself
}

type VendorInfo added in v1.0.26

type VendorInfo struct {
	VendorList      []ModVersion          // modules that contribute packages to the build, in order of appearance
	VendorReplaced  []ModVersion          // all replaced modules; may or may not also contribute packages
	VendorVersion   map[string]string     // module path → selected version (if known)
	VendorPkgModule map[string]ModVersion // package → containing module
	VendorMeta      map[ModVersion]vendorMetadata
	// contains filtered or unexported fields
}

func ParseVendor added in v1.0.26

func ParseVendor(dirOrFile string) (*VendorInfo, error)

ParseVendor reads the list of vendored modules from vendor/modules.txt.

func ParseVendorContent added in v1.0.26

func ParseVendorContent(content string) *VendorInfo

type Version added in v1.0.26

type Version struct {
	Major string // decimal
	Minor string // decimal or ""
	Patch string // decimal or ""
	Kind  string // "", "alpha", "beta", "rc"
	Pre   string // decimal or ""
}

see: https://cs.opensource.google/go/go/+/master:src/internal/gover/gover.go

func ParseVersion added in v1.0.26

func ParseVersion(x string) Version

Jump to

Keyboard shortcuts

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