minlib

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const GobinCmdBase = "gobin"
View Source
const GobinDirBase = ".gobin"
View Source
const ManifestFileBase = "Gobinfile"
View Source
const ManifestLockFileBase = "Gobinfile-lock"

Variables

View Source
var Goroot = sync.OnceValues(func() (gobinPath string, err error) {

	ver := "1.23.1"
	homeDir := v(os.UserHomeDir())
	sdkDirPath := filepath.Join(homeDir, "sdk")
	gorootPath := filepath.Join(sdkDirPath, "go"+ver)
	goCmdPath := filepath.Join(gorootPath, "bin", "go"+exeExt())
	if _, err := os.Stat(goCmdPath); err == nil {
		return gorootPath, nil
	}
	tempDir := v(os.MkdirTemp("", ""))
	defer (func() { v0(os.RemoveAll(tempDir)) })()
	arcPath := filepath.Join(tempDir, "temp.tgz")
	url := fmt.Sprintf("https://go.dev/dl/go%s.%s-%s.tar.gz", ver, runtime.GOOS, runtime.GOARCH)

	if runtime.GOOS == "windows" {
		arcPath = filepath.Join(tempDir, "temp.zip")
		url = fmt.Sprintf("https://go.dev/dl/go%s.%s-%s.zip", ver, runtime.GOOS, runtime.GOARCH)
	}
	cmd := exec.Command("curl"+exeExt(), "--location", "-o", arcPath, url)
	cmd.Stdout = os.Stderr
	cmd.Stderr = os.Stderr
	v0(cmd.Run())
	cmd = exec.Command("tar"+exeExt(), "-C", sdkDirPath, "-xzf", arcPath)
	cmd.Stdout = os.Stderr
	cmd.Stderr = os.Stderr
	v0(cmd.Run())
	v0(os.Rename(filepath.Join(sdkDirPath, "go"), gorootPath))
	return gorootPath, nil
})

Functions

func Command added in v0.1.8

func Command(name string, arg ...string) (cmd *exec.Cmd, err error)

func ConfDirPath

func ConfDirPath(opts ...ConfDirPathOption) (
	confDirPath string,
	gobinPath string,
	err error,
)

ConfDirPath returns the configuration directory path. If the global option is true, it returns the global (home) configuration directory path. This returns the directory which contains the manifest file. If no manifest file is found in any parent directory, it returns the directory which contains the go.mod file.

func EnsureGobinCmdInstalled added in v0.1.1

func EnsureGobinCmdInstalled(global bool) (cmdPath string, err error)

func EnsureInstalled

func EnsureInstalled(gobinPath string, pkgPath string, ver string, tags string, log *log.Logger, _ *log.Logger) (cmdPkgVerPath string, err error)

EnsureInstalled ensures that the program package is installed.

func GlobalConfDirPath added in v0.1.8

func GlobalConfDirPath() (confDirPath string, gobinPath string, err error)

func RunCommand added in v0.1.1

func RunCommand(name string, arg ...string) (execErr *exec.ExitError, err error)

Types

type ConfDirPathOption

type ConfDirPathOption func(*paramsT) error

func WithGlobal

func WithGlobal(f bool) ConfDirPathOption

func WithInitialDir

func WithInitialDir(initialDir string) ConfDirPathOption

type GoListOutput

type GoListOutput struct {
	Version string `json:"Version"`
}

GoListOutput represents the output of the `go list` command.

type PkgVerLockMapT

type PkgVerLockMapT map[string]string

func PkgVerLockMap

func PkgVerLockMap(dirPath string) (lockList PkgVerLockMapT, err error)

PkgVerLockMap returns the package version lock map.

Jump to

Keyboard shortcuts

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