gosdk

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

Package gosdk 提供查找本机 go sdk 路径的功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoDisableGoWork added in v0.0.3

func AutoDisableGoWork() error

AutoDisableGoWork 自动禁用 go work 功能

若当前项目未在 go.work 文件中定义,则设置环境变量 GOWORK = off

func Default

func Default(ctx context.Context) string

Default 返回 $PATH 里的 "go" 二进制文件的路径,若不存在,会返回空

func DefaultOrLatest

func DefaultOrLatest(ctx context.Context) string

DefaultOrLatest 查找 $PATH 里的 "go" 二进制文件的路径 或者是最高版本的 go 若没有,也会返回 "go"

func GoCmdEnv

func GoCmdEnv(goBin string, env []string) []string

GoCmdEnv 根据 goBin 路径返回设置了 GOROOT 的环境变量

func Latest

func Latest(ctx context.Context) string

Latest 返回最新版本的 Go 的路径,若不存在,会返回空

func LatestOrDefault

func LatestOrDefault(ctx context.Context) string

LatestOrDefault 返回最新版本,或者是 $PATH 里的 go 版本, 若没有,也会返回 "go"

func List

func List(ctx context.Context) []string

List 返回当前机器所有安装的,可用的 'go' 的地址 版本由高到低排序 若没有,会返回空

func MustAutoDisableGoWork added in v0.0.3

func MustAutoDisableGoWork()

MustAutoDisableGoWork AutoDisableGoWork 的快捷调用,若失败会 panic

func RunGo added in v0.0.6

func RunGo(ctx context.Context, root string)

RunGo 执行 go 命令

root: Go SDK 的目录,如 ~/sdk/go1.22.5/

func SetLogger added in v0.0.7

func SetLogger(l *log.Logger)

func TryAutoDisableGoWork added in v0.0.3

func TryAutoDisableGoWork()

TryAutoDisableGoWork AutoDisableGoWork 的快捷调用,若失败,会打印日志

func Update

func Update()

Update 更新默认的环境信息

Types

type SDK

type SDK struct {
	ExtDirs []string // 除了 ~/sdk/ 其他的 go sdk 根目录,可选
	// contains filtered or unexported fields
}

SDK 查找当前机器的 Go SDK 情况

func (*SDK) Default

func (gs *SDK) Default(ctx context.Context) string

Default 返回 $PATH 里的 "go" 二进制文件的路径,若不存在,会返回空

func (*SDK) DefaultOrLatest

func (gs *SDK) DefaultOrLatest(ctx context.Context) string

DefaultOrLatest 查找 $PATH 里的 go 或者是最高版本的 go 若没有,也会返回 "go"

func (*SDK) Find added in v0.0.6

func (gs *SDK) Find(ctx context.Context, version string) string

Find 查找指定号的 go 命令的地址,若查找不到会返回空字符串

version: go 版本号,如 1.21

返回如 /home/work/sdk/go1.21.12/bin/go

func (*SDK) Latest

func (gs *SDK) Latest(ctx context.Context) string

Latest 返回最新版本的 "go" 的路径,若不存在,会返回空

func (*SDK) LatestOrDefault

func (gs *SDK) LatestOrDefault(ctx context.Context) string

LatestOrDefault 返回最新版本 "go" 二进制文件的路径,或者是 $PATH 里的 go 版本 若没有,也会返回 "go"

func (*SDK) List

func (gs *SDK) List(ctx context.Context) []string

List 返回当前机器所有安装的,可用的 'go' 的地址 版本由高到低排序 若没有,会返回空