mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
28 lines
512 B
Go
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("GOPATH")
|
|
bin := filepath.Join(goroot, "bin")
|
|
if !pathx.FileExists(bin) {
|
|
gopath := os.Getenv("GOROOT")
|
|
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
|
|
}
|