package modindex
import "golang.org/x/tools/internal/modindex"
Package modindex contains code for building and searching an Index of the Go module cache.
Index ¶
- Constants
- Variables
- type Candidate
- type Entry
- type Field
- type Index
- func Read(gomodcache string) (*Index, error)
- func Update(gomodcache string) (*Index, error)
- func (ix *Index) Lookup(pkgName, name string, prefix bool) []Candidate
- func (ix *Index) LookupAll(pkgName string, names ...string) map[string][]Candidate
- func (ix *Index) String() string
- type LexType
Constants ¶
const CurrentVersion int = 0
CurrentVersion tells readers about the format of the index.
Variables ¶
var IndexDir string = func() string { var dir string if testing.Testing() { dir = os.TempDir() } else { var err error dir, err = os.UserCacheDir() if err != nil { dir = os.TempDir() } } dir = filepath.Join(dir, "goimports") if err := os.MkdirAll(dir, 0777); err != nil { log.Printf("failed to create modcache index dir: %v", err) } return dir }()
IndexDir is where the module index is stored. Each logical index entry consists of a pair of files:
- the "payload" (index-VERSION-XXX), whose name is randomized, holds the actual index; and
- the "link" (index-name-VERSION-HASH), whose name is predictable, contains the name of the payload file.
Since the link file is small (<512B), reads and writes to it may be assumed atomic.
Types ¶
type Candidate ¶
type Candidate struct {
PkgName string
Name string
Dir string
ImportPath string
Type LexType
Deprecated bool
// information for Funcs
Results int16 // how many results
Sig []Field // arg names and types
}
type Entry ¶
type Entry struct {
Dir string // package directory relative to GOMODCACHE; uses OS path separator
ImportPath string
PkgName string
Version string
Names []string // exported names and information
}
An Entry contains information for an import path.
type Field ¶
type Field struct {
Arg, Type string
}
type Index ¶
type Index struct {
Version int
GOMODCACHE string // absolute path of Go module cache dir
ValidAt time.Time // moment at which the index was up to date
Entries []Entry
}
Index is returned by Read.
func Read ¶
Read reads the latest version of the on-disk index for the specified Go module cache directory. If there is no index, it returns a nil Index and an fs.ErrNotExist error.
func Update ¶
Update updates the index for the specified Go module cache directory, creating it as needed. On success it returns the current index.
func (*Index) Lookup ¶
Lookup finds all the symbols in the index with the given PkgName and name. If prefix is true, it finds all of these with name as a prefix.
func (*Index) LookupAll ¶
LookupAll only returns those Candidates whose import path finds all the names.
func (*Index) String ¶
type LexType ¶
type LexType int8
Source Files ¶
directories.go index.go lookup.go modindex.go symbols.go
Directories ¶
| Path | Synopsis |
|---|---|
| internal/modindex/gomodindex | A command for building and maintaining the module cache a.out <flags> <command> <args> The commands are: 'update', which attempts to update an existing index, 'query', which looks up things in the index. |
- Version
- v0.39.0
- Published
- Nov 12, 2025
- Platform
- js/wasm
- Imports
- 25 packages
- Last checked
- 3 hours ago –
Tools for package owners.