tools: Index | Files

package gocommand

import ""

Package gocommand is a helper for calling the go command.


Package Files

invoke.go vendor.go version.go

func GoVersion Uses

func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error)

GoVersion checks the go version by running "go list" with modules off. It returns the X in Go 1.X.

type Invocation Uses

type Invocation struct {
    Verb       string
    Args       []string
    BuildFlags []string
    ModFlag    string
    ModFile    string
    Overlay    string
    // If CleanEnv is set, the invocation will run only with the environment
    // in Env, not starting with os.Environ.
    CleanEnv   bool
    Env        []string
    WorkingDir string
    Logf       func(format string, args ...interface{})

An Invocation represents a call to the go command.

type ModuleJSON Uses

type ModuleJSON struct {
    Path      string      // module path
    Replace   *ModuleJSON // replaced by this module
    Main      bool        // is this the main module?
    Indirect  bool        // is this module only an indirect dependency of main module?
    Dir       string      // directory holding files for this module, if any
    GoMod     string      // path to go.mod file for this module, if any
    GoVersion string      // go version used in module

ModuleJSON holds information about a module.

func VendorEnabled Uses

func VendorEnabled(ctx context.Context, inv Invocation, r *Runner) (*ModuleJSON, bool, error)

VendorEnabled reports whether vendoring is enabled. It takes a *Runner to execute Go commands with the supplied context.Context and Invocation. The Invocation can contain pre-defined fields, of which only Verb and Args are modified to run the appropriate Go command. Inspired by setDefaultBuildMod in modload/init.go

type Runner Uses

type Runner struct {
    // contains filtered or unexported fields

An Runner will run go command invocations and serialize them if it sees a concurrency error.

func (*Runner) Run Uses

func (runner *Runner) Run(ctx context.Context, inv Invocation) (*bytes.Buffer, error)

Run is a convenience wrapper around RunRaw. It returns only stdout and a "friendly" error.

func (*Runner) RunPiped Uses

func (runner *Runner) RunPiped(ctx context.Context, inv Invocation, stdout, stderr io.Writer) error

RunPiped runs the invocation serially, always waiting for any concurrent invocations to complete first.

func (*Runner) RunRaw Uses

func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error)

RunRaw runs the invocation, serializing requests only if they fight over go.mod changes.

Package gocommand imports 14 packages (graph) and is imported by 21 packages. Updated 2021-01-23. Refresh now. Tools for package owners.