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 + } +}