Skip to content

Commit

Permalink
chore: not using goproxy by default (#4613)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Jan 29, 2025
1 parent 9213b8a commit f669d84
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 97 deletions.
3 changes: 2 additions & 1 deletion tools/goctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tools/goctl/compare/compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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============================="
Expand Down
4 changes: 1 addition & 3 deletions tools/goctl/docker/docker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/example/rpc/multiple_rpc_service_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/example/rpc/single_rpc_service_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
44 changes: 0 additions & 44 deletions tools/goctl/migrate/proxy.go

This file was deleted.

50 changes: 23 additions & 27 deletions tools/goctl/migrate/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
log := func(err error) {
console.Warning("get latest versions failed, error: %+v", err)
}
resp, err := client.Get(fmt.Sprintf("%s/@v/list", repo))
if err != nil {
log(err)
return nil, err
}

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
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("%s", resp.Status)
log(err)
return nil, err
}
return []string{}, nil
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
}
15 changes: 2 additions & 13 deletions tools/goctl/quickstart/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
6 changes: 4 additions & 2 deletions tools/goctl/test/integration/model/mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/test/integration/model/mongo/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
4 changes: 2 additions & 2 deletions tools/goctl/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f669d84

Please sign in to comment.