fix: retrieve runtime gopath & goroot

This commit is contained in:
Kevin Franklin Kim 2025-06-03 16:28:45 +02:00
parent fbbed9b992
commit 9ba42b74c6
No known key found for this signature in database

View File

@ -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)
}