From b66f9f4b2c6b38e33c9a1371269587d0c050203f Mon Sep 17 00:00:00 2001 From: kun Date: Mon, 1 Mar 2021 17:52:55 +0800 Subject: [PATCH] fix: fix module cache dir --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 89bb9ab..ebb1620 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,6 @@ func init() { os.Setenv("GOSUMDB", "off") downloadRoot = getDownloadRoot() - os.Setenv("GOMODCACHE", downloadRoot) } func main() { @@ -121,7 +120,7 @@ func getDownloadRoot() string { GOPATH string } if cacheDir != "" { - os.Setenv("GOPATH", cacheDir) + os.Setenv("GOMODCACHE", filepath.Join(cacheDir, "pkg", "mod")) return filepath.Join(cacheDir, "pkg", "mod", "cache", "download") } if err := goJSON(&env, "go", "env", "-json", "GOPATH"); err != nil { @@ -131,6 +130,7 @@ func getDownloadRoot() string { if len(list) == 0 || list[0] == "" { log.Fatalf("missing $GOPATH") } + os.Setenv("GOMODCACHE", filepath.Join(list[0], "pkg", "mod")) return filepath.Join(list[0], "pkg", "mod", "cache", "download") }