Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotIndexed = errors.New("not in module index")
Functions ¶
func IsStandardPackage ¶
IsStandardPackage reports whether path is a standard package for the goroot and compiler using the module index if possible, and otherwise falling back to internal/goroot.IsStandardPackage
Types ¶
type Context ¶
type Context struct { GOARCH string // target architecture GOOS string // target operating system GOROOT string // Go root GOPATH string // Go paths // Dir is the caller's working directory, or the empty string to use // the current directory of the running process. In module mode, this is used // to locate the main module. // // If Dir is non-empty, directories passed to Import and ImportDir must // be absolute. Dir string CgoEnabled bool // whether cgo files are included UseAllFiles bool // use files regardless of //go:build lines, file names Compiler string // compiler to assume when computing target paths // The build, tool, and release tags specify build constraints // that should be considered satisfied when processing +build lines. // Clients creating a new context may customize BuildTags, which // defaults to empty, but it is usually an error to customize ToolTags or ReleaseTags. // ToolTags defaults to build tags appropriate to the current Go toolchain configuration. // ReleaseTags defaults to the list of Go releases the current release is compatible with. // BuildTags is not set for the Default build Context. // In addition to the BuildTags, ToolTags, and ReleaseTags, build constraints // consider the values of GOARCH and GOOS as satisfied tags. // The last element in ReleaseTags is assumed to be the current release. BuildTags []string ToolTags []string ReleaseTags []string // The install suffix specifies a suffix to use in the name of the installation // directory. By default it is empty, but custom builds that need to keep // their outputs separate can set InstallSuffix to do so. For example, when // using the race detector, the go command uses InstallSuffix = "race", so // that on a Linux/386 system, packages are written to a directory named // "linux_386_race" instead of the usual "linux_386". InstallSuffix string // JoinPath joins the sequence of path fragments into a single path. // If JoinPath is nil, Import uses filepath.Join. JoinPath func(elem ...string) string // SplitPathList splits the path list into a slice of individual paths. // If SplitPathList is nil, Import uses filepath.SplitList. SplitPathList func(list string) []string // IsAbsPath reports whether path is an absolute path. // If IsAbsPath is nil, Import uses filepath.IsAbs. IsAbsPath func(path string) bool // IsDir reports whether the path names a directory. // If IsDir is nil, Import calls os.Stat and uses the result's IsDir method. IsDir func(path string) bool // HasSubdir reports whether dir is lexically a subdirectory of // root, perhaps multiple levels below. It does not try to check // whether dir exists. // If so, HasSubdir sets rel to a slash-separated path that // can be joined to root to produce a path equivalent to dir. // If HasSubdir is nil, Import uses an implementation built on // filepath.EvalSymlinks. HasSubdir func(root, dir string) (rel string, ok bool) // ReadDir returns a slice of fs.FileInfo, sorted by Name, // describing the content of the named directory. // If ReadDir is nil, Import uses ioutil.ReadDir. ReadDir func(dir string) ([]fs.FileInfo, error) // OpenFile opens a file (not a directory) for reading. // If OpenFile is nil, Import uses os.Open. OpenFile func(path string) (io.ReadCloser, error) }
A Context specifies the supporting context for a build.
type IndexPackage ¶
type IndexPackage struct {
// contains filtered or unexported fields
}
IndexPackage holds the information in the index needed to load a package in a specific directory.
func GetPackage ¶
func GetPackage(modroot, pkgdir string) (*IndexPackage, error)
GetPackage returns the IndexPackage for the directory at the given path. It will return ErrNotIndexed if the directory should be read without using the index, for instance because the index is disabled, or the package is not in a module.
func (*IndexPackage) Import ¶
func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *build.Package, err error)
Import is the equivalent of build.Import given the information in Module.
func (*IndexPackage) IsDirWithGoFiles ¶
func (rp *IndexPackage) IsDirWithGoFiles() (_ bool, err error)
IsDirWithGoFiles is the equivalent of fsys.IsDirWithGoFiles using the information in the index.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module represents and encoded module index file. It is used to do the equivalent of build.Import of packages in the module and answer other questions based on the index file's data.
func GetModule ¶
GetModule returns the Module for the given modroot. It will return ErrNotIndexed if the directory should be read without using the index, for instance because the index is disabled, or the package is not in a module.
func (*Module) Package ¶
func (m *Module) Package(path string) *IndexPackage
Package and returns finds the package with the given path (relative to the module root). If the package does not exist, Package returns an IndexPackage that will return an appropriate error from its methods.
type MultiplePackageError ¶
type MultiplePackageError struct { Dir string // directory containing files Packages []string // package names found Files []string // corresponding files: Files[i] declares package Packages[i] }
MultiplePackageError describes a directory containing multiple buildable Go source files for multiple packages.
func (*MultiplePackageError) Error ¶
func (e *MultiplePackageError) Error() string