go-zero/tools/goctl/pkg/golang/bin.go

28 lines
512 B
Go
Raw Normal View History

2022-02-21 10:19:33 +08:00
package golang
import (
"go/build"
"os"
"path/filepath"
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
// GoBin returns a path of GOBIN.
func GoBin() string {
def := build.Default
2022-03-09 19:26:35 +08:00
goroot := os.Getenv("GOPATH")
2022-02-21 10:19:33 +08:00
bin := filepath.Join(goroot, "bin")
if !pathx.FileExists(bin) {
2022-03-09 19:26:35 +08:00
gopath := os.Getenv("GOROOT")
2022-02-21 10:19:33 +08:00
bin = filepath.Join(gopath, "bin")
}
if !pathx.FileExists(bin) {
bin = os.Getenv("GOBIN")
}
if !pathx.FileExists(bin) {
bin = filepath.Join(def.GOPATH, "bin")
}
return bin
}