use goproxy properly, remove files (#1903)

This commit is contained in:
Kevin Wan
2022-05-14 16:00:20 +08:00
committed by GitHub
parent 1e717f9f5c
commit 5d09cd0e7c
5 changed files with 26 additions and 11 deletions

View File

@@ -5,18 +5,19 @@ import (
"os/exec"
"runtime"
"github.com/zeromicro/go-zero/tools/goctl/util/env"
"github.com/zeromicro/go-zero/tools/goctl/vars"
)
const goproxy = "GOPROXY=https://goproxy.cn,direct"
func goStart(dir string) {
goproxy := "GOPROXY=https://goproxy.cn"
execCommand(dir, "go run .", goproxy)
execCommand(dir, "go run .", prepareGoProxyEnv()...)
}
func goModTidy(dir string) int {
goproxy := "GOPROXY=https://goproxy.cn"
log.Debug(">> go mod tidy")
return execCommand(dir, "go mod tidy", goproxy)
return execCommand(dir, "go mod tidy", prepareGoProxyEnv()...)
}
func execCommand(dir string, arg string, envArgs ...string) int {
@@ -33,3 +34,11 @@ func execCommand(dir string, arg string, envArgs ...string) int {
_ = cmd.Run()
return cmd.ProcessState.ExitCode()
}
func prepareGoProxyEnv(envArgs ...string) []string {
if env.InChina() {
return append(envArgs, goproxy)
}
return envArgs
}