go-zero/tools/goctl/pkg/golang/bin.go
2022-02-21 10:19:33 +08:00

28 lines
512 B
Go

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
goroot := os.Getenv("GOROOT")
bin := filepath.Join(goroot, "bin")
if !pathx.FileExists(bin) {
gopath := os.Getenv("GOPATH")
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
}