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

@@ -67,7 +67,7 @@ func (m micro) start() {
goModTidy(projectDir)
sg := service.NewServiceGroup()
sg.Add(serviceImpl{func() {
log.Debug(">> Ready to start an zRPC server...")
log.Debug(">> Ready to start a zRPC server...")
goStart(zRPCWorkDir)
}})
sg.Add(serviceImpl{func() {

View File

@@ -73,7 +73,7 @@ func (m mono) start() {
if !m.callRPC {
goModTidy(projectDir)
}
log.Debug(">> Ready to start an api server...")
log.Debug(">> Try to execute 'curl --request POST http://127.0.0.1:8888/ping' after service startup...")
log.Debug(">> Ready to start an API server...")
log.Debug(">> Run 'curl -X POST http://127.0.0.1:8888/ping' after service startup...")
goStart(apiWorkDir)
}

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
}