From 9ba42b74c697b3b1be3d78d60600b3721a8c60d6 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Tue, 3 Jun 2025 16:28:45 +0200 Subject: [PATCH] fix: retrieve runtime gopath & goroot --- cmd/gotsrpc/gotsrpc.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/gotsrpc/gotsrpc.go b/cmd/gotsrpc/gotsrpc.go index bea65c5..aa107ac 100644 --- a/cmd/gotsrpc/gotsrpc.go +++ b/cmd/gotsrpc/gotsrpc.go @@ -1,10 +1,11 @@ package main import ( + "bytes" "flag" "fmt" - "go/build" "os" + "os/exec" "github.com/foomo/gotsrpc/v2" "github.com/foomo/gotsrpc/v2/config" @@ -35,11 +36,26 @@ func main() { } gotsrpc.ReaderTrace = *flagDebug + var goRoot string + var goPath string + if out, err := exec.Command("go", "env", "GOROOT").Output(); err != nil { + fmt.Println("failed to retrieve GOROOT", err.Error()) + os.Exit(1) + } else { + goRoot = string(bytes.TrimSpace(out)) + } + if out, err := exec.Command("go", "env", "GOPATH").Output(); err != nil { + fmt.Println("failed to retrieve GOPATH", err.Error()) + os.Exit(1) + } else { + goPath = string(bytes.TrimSpace(out)) + } + conf, err := config.LoadConfigFile(args[0]) if err != nil { fmt.Fprintln(os.Stderr, "config load error, could not load config from", args[0], ":", err) os.Exit(2) } - gotsrpc.Build(conf, build.Default.GOPATH, build.Default.GOROOT) + gotsrpc.Build(conf, goPath, goRoot) }