Skip to content

Commit

Permalink
warn about slow GOPROXY=direct setting
Browse files Browse the repository at this point in the history
  • Loading branch information
stapelberg committed Nov 5, 2023
1 parent dceb56e commit c2c21f6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packer/gotool.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,30 @@ func BuildDirOrMigrate(importPath string) (string, error) {
return buildDir, nil
}

func warnWithoutProxy() {
goproxy := exec.Command("go", "env", "GOPROXY")
goproxy.Env = Env()
goproxy.Stderr = os.Stderr
if logExec {
log.Printf("getIncomplete: %v", goproxy.Args)
}
out, err := goproxy.Output()
if err != nil {
log.Printf("%v: %v", goproxy.Args, err)
}
if strings.TrimSpace(string(out)) != "direct" {
return
}
fmt.Println()
log.Printf("WARNING: you’re using GOPROXY=direct, which means " +
"the go tool needs to work with Git repositories, which is " +
"inefficient and slow. Consider enabling the Go Proxy: " +
"go env -w GOPROXY=https://proxy.golang.org,direct")
}

func getIncomplete(buildDir string, incomplete []string) error {
warnWithoutProxy()

log.Printf("getting incomplete packages %v", incomplete)
cmd := exec.Command("go",
append([]string{
Expand Down

0 comments on commit c2c21f6

Please sign in to comment.