package modindex

import "golang.org/x/tools/internal/modindex"

Package modindex contains code for building and searching an index to the Go module cache. The directory containing the index, returned by IndexDir(), contains a file index-name-<ver> that contains the name of the current index. We believe writing that short file is atomic. ReadIndex reads that file to get the file name of the index. WriteIndex writes an index with a unique name and then writes that name into a new version of index-name-<ver>. (<ver> stands for the CurrentVersion of the index format.)

Index

Constants

const CurrentVersion int = 0

CurrentVersion tells readers about the format of the index.

Variables

var IndexDir string

IndexDir is where the module index is stored.

Functions

func Create

func Create(cachedir string) error

Create always creates a new index for the go module cache that is in cachedir.

func DirToImportPathVersion

func DirToImportPathVersion(dir Relpath) (string, string, error)

DirToImportPathVersion computes import path and semantic version

func Update

func Update(cachedir string) (bool, error)

Update the index for the go module cache that is in cachedir, If there is no existing index it will build one. If there are changed directories since the last index, it will write a new one and return true. Otherwise it returns false.

Types

type Abspath

type Abspath string // absolute paths

distinguish various types of directory names. It's easy to get confused.

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        Relpath // directory in modcache
	ImportPath string
	PkgName    string
	Version    string
	//ModTime    STime    // is this useful?
	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
	Cachedir Abspath   // The directory containing the module cache
	Changed  time.Time // The index is up to date as of Changed
	Entries  []Entry
}

Index is returned by ReadIndex().

func ReadIndex

func ReadIndex(cachedir string) (*Index, error)

ReadIndex reads the latest version of the on-disk index for the cache directory cd. It returns (nil, nil) if there is no index, but returns a non-nil error if the index exists but could not be read.

func (*Index) Lookup

func (ix *Index) Lookup(pkg, 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

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

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

type LexType

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

type Relpath

type Relpath string // paths with GOMODCACHE prefix removed

Source Files

directories.go index.go lookup.go modindex.go symbols.go types.go

Directories

PathSynopsis
internal/modindex/gomodindexA command for building and maintaing the module cache a.out <flags> <command> <args> The commands are 'create' which builds a new index, 'update', which attempts to update an existing index, 'query', which looks up things in the index.
Version
v0.30.0 (latest)
Published
Feb 10, 2025
Platform
linux/amd64
Imports
25 packages
Last checked
8 hours ago

Tools for package owners.