7
7
"net/http"
8
8
"os"
9
9
"os/exec"
10
+ "slices"
10
11
"strings"
11
12
12
13
"golang.org/x/mod/semver"
@@ -63,22 +64,23 @@ func isUpdateRequired(current string, latest string) bool {
63
64
}
64
65
65
66
func getLatestVersion () (string , error ) {
66
- goproxy := "https://proxy.golang.org"
67
+ goproxyDefault := "https://proxy.golang.org"
68
+ goproxy := goproxyDefault
67
69
cmd := exec .Command ("go" , "env" , "GOPROXY" )
68
70
output , err := cmd .Output ()
69
71
if err == nil {
70
72
goproxy = strings .TrimSpace (string (output ))
71
73
}
72
74
73
- if goproxy == "" {
74
- goproxy = "https://proxy.golang.org"
75
+ proxies := strings .Split (goproxy , "," )
76
+ if ! slices .Contains (proxies , goproxyDefault ) {
77
+ proxies = append (proxies , goproxyDefault )
75
78
}
76
79
77
- proxies := strings .Split (goproxy , "," )
78
80
for _ , proxy := range proxies {
79
81
proxy = strings .TrimSpace (proxy )
80
82
proxy = strings .TrimRight (proxy , "/" )
81
- if proxy == "direct" {
83
+ if proxy == "direct" || proxy == "off" {
82
84
continue
83
85
}
84
86
@@ -91,16 +93,16 @@ func getLatestVersion() (string, error) {
91
93
92
94
body , err := io .ReadAll (resp .Body )
93
95
if err != nil {
94
- return "" , err
96
+ continue
95
97
}
96
98
97
99
var version struct { Version string }
98
100
if err = json .Unmarshal (body , & version ); err != nil {
99
- return "" , err
101
+ continue
100
102
}
101
103
102
104
return version .Version , nil
103
105
}
104
106
105
- return "" , fmt .Errorf ("failed to fetch latest version from proxies " )
107
+ return "" , fmt .Errorf ("failed to fetch latest version" )
106
108
}
0 commit comments