modindex

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package modindex contains code for building and searching an Index of the Go module cache.

Index

Constants

View Source
const CurrentVersion int = 0

CurrentVersion tells readers about the format of the index.

Variables

View Source
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.

Functions

This section is empty.

Types

type Candidate added in v0.27.0

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 added in v0.27.0

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 added in v0.36.0

func Read(gomodcache string) (*Index, error)

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 added in v0.27.0

func Update(gomodcache string) (*Index, error)

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 added in v0.27.0

func (ix *Index) Lookup(pkgName, name string, prefix bool) []Candidate

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 added in v0.30.0

func (ix *Index) LookupAll(pkgName string, names ...string) map[string][]Candidate

LookupAll only returns those Candidates whose import path finds all the names.

func (*Index) String added in v0.36.0

func (ix *Index) String() string

type LexType added in v0.27.0

type LexType int8
const (
	Const LexType = iota
	Var
	Type
	Func
)

Directories

Path Synopsis
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.
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.

Jump to

Keyboard shortcuts

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