From 0fe025ba1ec0f0ba4d9ab15003f8418a95367a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 22 May 2022 21:06:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20go=20=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang.go | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 golang.go diff --git a/golang.go b/golang.go new file mode 100644 index 0000000..31c8005 --- /dev/null +++ b/golang.go @@ -0,0 +1,126 @@ +// Package command ... +// +// Description : command ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2022-05-22 20:03 +package command + +import ( + "fmt" + "strings" + + "git.zhangdeman.cn/zhangdeman/command/define" +) + +// Golang 指令实例 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:04 2022/5/22 +func Golang(workDir string) *golang { + return &golang{ + workDir: workDir, + goCmdPath: "go", + } +} + +type golang struct { + workDir string + goCmdPath string +} + +// ResetGoCmdPath 重置go命令路径 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:13 2022/5/22 +func (g *golang) ResetGoCmdPath(cmdPath string) *golang { + g.goCmdPath = cmdPath + return g +} + +// ModInit go mod init 指令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:10 2022/5/22 +func (g *golang) ModInit(modPath string) *define.Result { + return Execute(g.workDir, g.goCmdPath, []string{"mod", "init", modPath}) +} + +// ModTidy go mod tidy 命令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:17 2022/5/22 +func (g *golang) ModTidy() *define.Result { + return Execute(g.workDir, g.goCmdPath, []string{"mod", "tidy"}) +} + +// ModReplace 映射包 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:22 2022/5/22 +func (g *golang) ModReplace(sourcePath string, replacePath string) *define.Result { + return Execute(g.workDir, g.goCmdPath, []string{ + "mod", + "edit", + "-replace", + fmt.Sprintf("%s=%s", sourcePath, replacePath), + }) +} + +// Proxy 设置 GOPROXY, 若要清空,proxyList设置为空即可 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:51 2022/5/22 +func (g *golang) Proxy(proxyList []string) *golang { + _ = Export().Set("GOPROXY", strings.Join(proxyList, ",")) + return g +} + +// NoProxy 指定代码仓库不经过proxy +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:53 2022/5/22 +func (g *golang) NoProxy(noProxyList []string) *golang { + _ = Export().Set("GONOPROXY", strings.Join(noProxyList, ",")) + return g +} + +// Private 设置私有的代码仓库 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:55 2022/5/22 +func (g *golang) Private(privateList []string) *golang { + _ = Export().Set("GOPRIVATE", strings.Join(privateList, ",")) + return g +} + +// NoSumDB 不做sumdb校验 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:59 2022/5/22 +func (g *golang) NoSumDB(noSumDBList []string) *golang { + _ = Export().Set("GONOSUMDB", strings.Join(noSumDBList, ",")) + return g +} + +// GetRecommendGoProxyList 获取推荐的 GOPROXY列表 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:00 2022/5/22 +func (g *golang) GetRecommendGoProxyList() []string { + return []string{ + "https://mirrors.aliyun.com/goproxy/", // 阿里云proxy + "https://goproxy.cn/", // 基于七牛云CDN + } +}