Closed skovranek closed 2 months ago
I had some fun looking into this
As of go 1.13, default GORPOXY (unset GOPROXY and GOPROXY="") is set to https://proxy.golang.org,direct
, and the version check still works on go 1.22.6 (not tested against 1.23)
What also works is against conforming proxies like
Specifically what doesn't work is GOPROXY=direct
and GOPROXY=off
Fully respecting GOPROXY doesn't seem like a viable solution, as GOPROXY=off means "no network"
What would be the easiest fix is checking if the proxy list contains https://proxy.golang.org
and if not, append it to the proxies list like this:
diff --git a/version/version.go b/version/version.go
index 1eb8093..4292aa8 100644
--- a/version/version.go
+++ b/version/version.go
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/exec"
+ "slices"
"strings"
"golang.org/x/mod/semver"
@@ -63,7 +64,8 @@ func isUpdateRequired(current string, latest string) bool {
}
func getLatestVersion() (string, error) {
- goproxy := "https://proxy.golang.org"
+ goproxyDefault := "https://proxy.golang.org"
+ goproxy := goproxyDefault
cmd := exec.Command("go", "env", "GOPROXY")
output, err := cmd.Output()
if err == nil {
@@ -71,14 +73,18 @@ func getLatestVersion() (string, error) {
}
if goproxy == "" {
- goproxy = "https://proxy.golang.org"
+ goproxy = goproxyDefault
}
proxies := strings.Split(goproxy, ",")
+ if !slices.Contains(proxies, goproxyDefault) {
+ proxies = append(proxies, goproxyDefault)
+ }
+
for _, proxy := range proxies {
proxy = strings.TrimSpace(proxy)
proxy = strings.TrimRight(proxy, "/")
- if proxy == "direct" {
+ if proxy == "direct" || proxy == "off" {
continue
}
A different option would be to expose an API from something like api.boot.dev/github.com/bootdotdev/bootdev/@latest
and simply return the version from there
As a last mention: the github api
tag_name
in json, so it would still not quite fit the current code's Version
Unmarshall, see here)Just found out why on Fedora it doesn't work, Fedora's RPM package has a patch that changes GOPROXY's default to direct
per discord: https://discord.com/channels/551921866173054977/1277003758450114580/1277003758450114580
possible unhandled edge cases: