rungo

package
v0.0.0-...-ba0629f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package rungo provides tools to run the Go toolchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListGoVersions

func ListGoVersions(ctx context.Context) ([]string, error)

ListGoVersions gets a list of all current Go versions by downloading the Golang download page and scanning it for Go versions. Includes beta and RC versions, as well as normal point releases. See https://golang.org/dl (all versions are listed under "Archived versions") or https://go.dev/dl/?mode=json&include=all

Types

type GoInstallation

type GoInstallation struct {
	// Go version, formatted as "Major.Minor.Rev" if Rev is 0,
	// otherwise "Major.Minor"
	Version string
	// $GOPATH to use when invoking `go install`.
	// Determines where the wrapper toolchain binary is installed.
	InstallGopath string
	// $GOCACHE to use when invoking `go install`.
	// In other contexts, this is usually `$HOME/.cache/go-build`
	// if no custom cache has been set.
	InstallGocache string
	// Optional location to install the actual toolchain.
	// If this is not specified, it will be installed to `$HOME/sdk/goX.X.X/`
	InstallLocation string
}

GoInstallation configures a call to (*GoInstallation).Install, allowing callers to specify the installation/cache directories used, in addition to the actual toolchain version.

func (*GoInstallation) Install

func (i *GoInstallation) Install(ctx context.Context) (string, []byte, error)

Install installs the "go" toolchain for the given Go version by using the existing tooling in golang.org/dl/goX.X.X.

At a high level, this:

  • runs `go install` using the host Go toolchain, installing a wrapper program to `<i.InstallGopath>/bin`.
  • runs `<wrapper> download`, which downloads and extracts the compiled Go toolchain to `<i.InstallLocation>/sdk/goX.X.X`, or `$HOME/sdk/goX.X.X/` if that is not specified

If an error occurs, the function returns the error value in the third return value. If the error occurs while as the result of running a command, then its output is also returned in the second return value. Otherwise, if installation is successful, this function returns the absolute path to the binary in the first return value.

This function can be called if the toolchain is already installed; in that case it will return early.

Note: when using the Go binary that this function returns, the $HOME environment variable must be set to point to the same value as `i.InstallLocation` (if a custom value was given).

Directories

Path Synopsis
Package matrix provides a utility for running a single Go command
Package matrix provides a utility for running a single Go command

Jump to

Keyboard shortcuts

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