Skip to content

Commit f133029

Browse files
authored
Get GOCACHE from environment if possible (#5)
1 parent 7e3e754 commit f133029

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"log"
66
"log/slog"
7+
"os"
78
"os/exec"
89
"strings"
910
"sync"
@@ -33,6 +34,12 @@ var cli struct {
3334

3435
// GOCACHE returns the Go build cache directory.
3536
var GOCACHE = sync.OnceValue(func() string {
37+
// in theory, someone might not have go in the PATH
38+
if v := os.Getenv("GOCACHE"); v != "" {
39+
return v
40+
}
41+
42+
// that handles `go env -w` and the default value
3643
b, err := exec.Command("go", "env", "GOCACHE").Output()
3744
if err != nil {
3845
panic(err)

0 commit comments

Comments
 (0)