77 "net/http"
88 "os"
99 "os/exec"
10+ "slices"
1011 "strings"
1112
1213 "golang.org/x/mod/semver"
@@ -63,22 +64,23 @@ func isUpdateRequired(current string, latest string) bool {
6364}
6465
6566func getLatestVersion () (string , error ) {
66- goproxy := "https://proxy.golang.org"
67+ goproxyDefault := "https://proxy.golang.org"
68+ goproxy := goproxyDefault
6769 cmd := exec .Command ("go" , "env" , "GOPROXY" )
6870 output , err := cmd .Output ()
6971 if err == nil {
7072 goproxy = strings .TrimSpace (string (output ))
7173 }
7274
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 )
7578 }
7679
77- proxies := strings .Split (goproxy , "," )
7880 for _ , proxy := range proxies {
7981 proxy = strings .TrimSpace (proxy )
8082 proxy = strings .TrimRight (proxy , "/" )
81- if proxy == "direct" {
83+ if proxy == "direct" || proxy == "off" {
8284 continue
8385 }
8486
@@ -91,16 +93,16 @@ func getLatestVersion() (string, error) {
9193
9294 body , err := io .ReadAll (resp .Body )
9395 if err != nil {
94- return "" , err
96+ continue
9597 }
9698
9799 var version struct { Version string }
98100 if err = json .Unmarshal (body , & version ); err != nil {
99- return "" , err
101+ continue
100102 }
101103
102104 return version .Version , nil
103105 }
104106
105- return "" , fmt .Errorf ("failed to fetch latest version from proxies " )
107+ return "" , fmt .Errorf ("failed to fetch latest version" )
106108}
0 commit comments