mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-07 15:10:01 +08:00
chore: not using goproxy by default (#4613)
This commit is contained in:
@@ -3,7 +3,8 @@ FROM golang:alpine AS builder
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
# if you are in China, you can use the following command to speed up the download
|
||||
# ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
|
||||
@@ -31,7 +31,6 @@ if [ -d $WD ]; then
|
||||
fi
|
||||
|
||||
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
||||
execute_command 'export GOPROXY="https://goproxy.cn,direct"'
|
||||
execute_command "export GOBIN=$BIN"
|
||||
|
||||
echo "=======================install goctl============================="
|
||||
|
||||
@@ -3,10 +3,8 @@ FROM golang:{{.Version}}alpine AS builder
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
{{- end}}{{if .HasTimezone}}
|
||||
{{if .HasTimezone}}
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
{{- end}}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
||||
go mod tidy
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Tidy failed"
|
||||
|
||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
||||
go mod tidy
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Tidy failed"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildVersion is the version of goctl.
|
||||
const BuildVersion = "1.8.0"
|
||||
const BuildVersion = "1.7.7"
|
||||
|
||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultProxy = "https://goproxy.cn"
|
||||
defaultProxies = []string{defaultProxy}
|
||||
)
|
||||
|
||||
func goProxy() []string {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return defaultProxies
|
||||
}
|
||||
|
||||
proxy, err := execx.Run("go env GOPROXY", wd)
|
||||
if err != nil {
|
||||
return defaultProxies
|
||||
}
|
||||
list := strings.FieldsFunc(proxy, func(r rune) bool {
|
||||
return r == '|' || r == ','
|
||||
})
|
||||
var ret []string
|
||||
for _, item := range list {
|
||||
if len(item) == 0 {
|
||||
continue
|
||||
}
|
||||
_, err = url.Parse(item)
|
||||
if err == nil && !stringx.Contains(ret, item) {
|
||||
ret = append(ret, item)
|
||||
}
|
||||
}
|
||||
if !stringx.Contains(ret, defaultProxy) {
|
||||
ret = append(ret, defaultProxy)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -15,33 +15,29 @@ var client = http.Client{
|
||||
}
|
||||
|
||||
func getLatest(repo string, verbose bool) ([]string, error) {
|
||||
proxies := goProxy()
|
||||
for _, proxy := range proxies {
|
||||
if verbose {
|
||||
console.Info("use go proxy %q", proxy)
|
||||
}
|
||||
log := func(err error) {
|
||||
console.Warning("get latest versions failed from proxy %q, error: %+v", proxy, err)
|
||||
}
|
||||
resp, err := client.Get(fmt.Sprintf("%s/%s/@v/list", proxy, repo))
|
||||
if err != nil {
|
||||
log(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log(fmt.Errorf("%s", resp.Status))
|
||||
continue
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log(err)
|
||||
continue
|
||||
}
|
||||
versionStr := string(data)
|
||||
versions := strings.Fields(versionStr)
|
||||
return versions, nil
|
||||
log := func(err error) {
|
||||
console.Warning("get latest versions failed, error: %+v", err)
|
||||
}
|
||||
return []string{}, nil
|
||||
resp, err := client.Get(fmt.Sprintf("%s/@v/list", repo))
|
||||
if err != nil {
|
||||
log(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
err = fmt.Errorf("%s", resp.Status)
|
||||
log(err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
versionStr := string(data)
|
||||
versions := strings.Fields(versionStr)
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
@@ -5,19 +5,16 @@ 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) {
|
||||
execCommand(dir, "go run .", prepareGoProxyEnv()...)
|
||||
execCommand(dir, "go run .")
|
||||
}
|
||||
|
||||
func goModTidy(dir string) int {
|
||||
log.Debug(">> go mod tidy")
|
||||
return execCommand(dir, "go mod tidy", prepareGoProxyEnv()...)
|
||||
return execCommand(dir, "go mod tidy")
|
||||
}
|
||||
|
||||
func execCommand(dir, arg string, envArgs ...string) int {
|
||||
@@ -34,11 +31,3 @@ func execCommand(dir, 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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
FROM golang:1.22-alpine
|
||||
|
||||
ENV TZ Asia/Shanghai
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
# set timezone if you need
|
||||
# ENV TZ Asia/Shanghai
|
||||
# if you are in China, you can use the following command to speed up the download
|
||||
# ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
WORKDIR /app
|
||||
COPY goctl /usr/bin/
|
||||
|
||||
@@ -23,7 +23,7 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# go mod tidy
|
||||
GOPROXY=https://goproxy.cn && go mod tidy
|
||||
go mod tidy
|
||||
|
||||
# code inspection
|
||||
go test -race ./...
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
// upgrade gets the latest goctl by
|
||||
// go install github.com/zeromicro/go-zero/tools/goctl@latest
|
||||
func upgrade(_ *cobra.Command, _ []string) error {
|
||||
cmd := `GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
cmd := `go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd = `set GOPROXY=https://goproxy.cn,direct && go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
cmd = `go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
}
|
||||
info, err := execx.Run(cmd, "")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user