Help us shape the future of Go! Take the 2026 Go Developer Survey

resolve

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package resolve finds the tool a name stands for and asks go whether it can run.

A Resolver maps a tool name, as the user gave it (possibly an alias), to the modfile that serves it and the package and binary behind it. A Prober launches the tool through `go tool` to see whether it runs. Both take their seams as fields (the modfile parser, the manifest lookup, the go runner), so a test supplies fakes and no go process runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manifest

type Manifest interface {
	Tool(name string) (manifest.Tool, bool)
}

Manifest is the part of the manifest a Resolver reads.

type MissingError

type MissingError struct {
	Path string // relative to the project root
}

MissingError reports that the modfile serving a tool does not exist. The Ref returned with it is still filled in, so a caller can say where it looked.

func (*MissingError) Error

func (e *MissingError) Error() string

func (*MissingError) Unwrap

func (e *MissingError) Unwrap() error

Unwrap lets errors.Is(err, fs.ErrNotExist) match.

type Prober

type Prober struct {
	Resolver *Resolver
	Go       gocmd.Runner
	Offline  bool // GOPROXY=off, so a missing module fails fast
}

Prober asks go whether tools run. It never runs a tool for `install`: the install verify is `go tool -n`, which builds without running.

func (*Prober) Probe

func (p *Prober) Probe(ctx context.Context, name string) string

Probe says whether `go tool` can launch name under the project's strategy: "" when it can, else a one-line reason.

Read-only: stdin is empty, GOTOOLCHAIN=local so a toolchain is never downloaded, and GOPROXY=off when offline.

func (*Prober) Runs

func (p *Prober) Runs(ctx context.Context, name string) bool

Runs launches the tool with each probe argument until one exits 0. A tool that has none of them (many exit 2 on an unknown flag) still counts when go can build it, since that is all `go tool -n` asks of it. It is what `check` reports.

type Ref

type Ref struct {
	Name       string // name as given (manifest name, possibly an alias)
	Package    string // tool directive serving Name; "" when none is declared
	Binary     string // name passed to `go tool`
	ModFile    string // absolute modfile path
	ModFileRel string // modfile path relative to the project root, slash-separated
}

Ref is a tool name resolved against the tools directory.

type Resolver

type Resolver struct {
	Root     string
	Layout   strategy.Layout
	ModFiles modparser.Parser
	Manifest Manifest // may be nil
}

Resolver resolves tool names for one project.

func (*Resolver) Call

func (r *Resolver) Call(ref Ref, args ...string) gocmd.Call

Call is the `go tool` invocation for ref, the single definition shared by the probes and exec:

unified  go tool <bin>                    in <dir>
split    go tool -modfile=<abs> <bin>     in the project root
module   go tool <bin>                    in <dir>/<name>

args are appended after the binary.

func (*Resolver) Resolve

func (r *Resolver) Resolve(name string) (Ref, error)

Resolve finds the modfile, package and binary serving name.

split and module: the tool's own modfile holds one directive, which serves it.

unified: the shared go.mod holds many directives. The manifest entry's package is used when it is declared there; without a manifest entry, the directive whose inferred binary name equals name. Taking the first directive would run the wrong tool whenever the project has two.

Jump to

Keyboard shortcuts

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