mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
use goproxy properly, remove files (#1903)
This commit is contained in:
parent
1e717f9f5c
commit
5d09cd0e7c
@ -7,11 +7,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
"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"
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,7 +19,6 @@ const (
|
|||||||
dockerfileName = "Dockerfile"
|
dockerfileName = "Dockerfile"
|
||||||
etcDir = "etc"
|
etcDir = "etc"
|
||||||
yamlEtx = ".yaml"
|
yamlEtx = ".yaml"
|
||||||
cstOffset = 60 * 60 * 8 // 8 hours offset for Chinese Standard Time
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Docker describes a dockerfile
|
// Docker describes a dockerfile
|
||||||
@ -152,10 +151,9 @@ func generateDockerfile(goFile, base string, port int, version, timezone string,
|
|||||||
builder.WriteString(`, "` + arg + `"`)
|
builder.WriteString(`, "` + arg + `"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, offset := time.Now().Zone()
|
|
||||||
t := template.Must(template.New("dockerfile").Parse(text))
|
t := template.Must(template.New("dockerfile").Parse(text))
|
||||||
return t.Execute(out, Docker{
|
return t.Execute(out, Docker{
|
||||||
Chinese: offset == cstOffset,
|
Chinese: env.InChina(),
|
||||||
GoRelPath: projPath,
|
GoRelPath: projPath,
|
||||||
GoFile: goFile,
|
GoFile: goFile,
|
||||||
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
||||||
|
@ -67,7 +67,7 @@ func (m micro) start() {
|
|||||||
goModTidy(projectDir)
|
goModTidy(projectDir)
|
||||||
sg := service.NewServiceGroup()
|
sg := service.NewServiceGroup()
|
||||||
sg.Add(serviceImpl{func() {
|
sg.Add(serviceImpl{func() {
|
||||||
log.Debug(">> Ready to start an zRPC server...")
|
log.Debug(">> Ready to start a zRPC server...")
|
||||||
goStart(zRPCWorkDir)
|
goStart(zRPCWorkDir)
|
||||||
}})
|
}})
|
||||||
sg.Add(serviceImpl{func() {
|
sg.Add(serviceImpl{func() {
|
||||||
|
@ -73,7 +73,7 @@ func (m mono) start() {
|
|||||||
if !m.callRPC {
|
if !m.callRPC {
|
||||||
goModTidy(projectDir)
|
goModTidy(projectDir)
|
||||||
}
|
}
|
||||||
log.Debug(">> Ready to start an api server...")
|
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(">> Run 'curl -X POST http://127.0.0.1:8888/ping' after service startup...")
|
||||||
goStart(apiWorkDir)
|
goStart(apiWorkDir)
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,19 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/env"
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const goproxy = "GOPROXY=https://goproxy.cn,direct"
|
||||||
|
|
||||||
func goStart(dir string) {
|
func goStart(dir string) {
|
||||||
goproxy := "GOPROXY=https://goproxy.cn"
|
execCommand(dir, "go run .", prepareGoProxyEnv()...)
|
||||||
execCommand(dir, "go run .", goproxy)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func goModTidy(dir string) int {
|
func goModTidy(dir string) int {
|
||||||
goproxy := "GOPROXY=https://goproxy.cn"
|
|
||||||
log.Debug(">> go mod tidy")
|
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 {
|
func execCommand(dir string, arg string, envArgs ...string) int {
|
||||||
@ -33,3 +34,11 @@ func execCommand(dir string, arg string, envArgs ...string) int {
|
|||||||
_ = cmd.Run()
|
_ = cmd.Run()
|
||||||
return cmd.ProcessState.ExitCode()
|
return cmd.ProcessState.ExitCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prepareGoProxyEnv(envArgs ...string) []string {
|
||||||
|
if env.InChina() {
|
||||||
|
return append(envArgs, goproxy)
|
||||||
|
}
|
||||||
|
|
||||||
|
return envArgs
|
||||||
|
}
|
||||||
|
8
tools/goctl/util/env/env.go
vendored
8
tools/goctl/util/env/env.go
vendored
@ -6,6 +6,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||||
)
|
)
|
||||||
@ -16,8 +17,15 @@ const (
|
|||||||
binProtoc = "protoc"
|
binProtoc = "protoc"
|
||||||
binProtocGenGo = "protoc-gen-go"
|
binProtocGenGo = "protoc-gen-go"
|
||||||
binProtocGenGrpcGo = "protoc-gen-go-grpc"
|
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
|
// LookUpGo searches an executable go in the directories
|
||||||
// named by the GOROOT/bin or PATH environment variable.
|
// named by the GOROOT/bin or PATH environment variable.
|
||||||
func LookUpGo() (string, error) {
|
func LookUpGo() (string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user