use goproxy properly, remove files (#1903)

master
Kevin Wan 3 years ago committed by GitHub
parent 1e717f9f5c
commit 5d09cd0e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,11 +7,11 @@ import (
"path/filepath"
"strings"
"text/template"
"time"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"github.com/zeromicro/go-zero/tools/goctl/util"
"github.com/zeromicro/go-zero/tools/goctl/util/env"
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
@ -19,7 +19,6 @@ const (
dockerfileName = "Dockerfile"
etcDir = "etc"
yamlEtx = ".yaml"
cstOffset = 60 * 60 * 8 // 8 hours offset for Chinese Standard Time
)
// Docker describes a dockerfile
@ -152,10 +151,9 @@ func generateDockerfile(goFile, base string, port int, version, timezone string,
builder.WriteString(`, "` + arg + `"`)
}
_, offset := time.Now().Zone()
t := template.Must(template.New("dockerfile").Parse(text))
return t.Execute(out, Docker{
Chinese: offset == cstOffset,
Chinese: env.InChina(),
GoRelPath: projPath,
GoFile: goFile,
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),

@ -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() {

@ -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)
}

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

@ -6,6 +6,7 @@ import (
"path/filepath"
"runtime"
"strings"
"time"
"github.com/zeromicro/go-zero/tools/goctl/vars"
)
@ -16,8 +17,15 @@ const (
binProtoc = "protoc"
binProtocGenGo = "protoc-gen-go"
binProtocGenGrpcGo = "protoc-gen-go-grpc"
cstOffset = 60 * 60 * 8 // 8 hours offset for Chinese Standard Time
)
// InChina returns whether the current time is in China Standard Time.
func InChina() bool {
_, offset := time.Now().Zone()
return offset == cstOffset
}
// LookUpGo searches an executable go in the directories
// named by the GOROOT/bin or PATH environment variable.
func LookUpGo() (string, error) {

Loading…
Cancel
Save