Feature: Add goctl env (#1557)
This commit is contained in:
27
tools/goctl/pkg/golang/bin.go
Normal file
27
tools/goctl/pkg/golang/bin.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
}
|
||||
17
tools/goctl/pkg/golang/install.go
Normal file
17
tools/goctl/pkg/golang/install.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package golang
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func Install(git string) error {
|
||||
cmd := exec.Command("go", "install", git)
|
||||
env := os.Environ()
|
||||
env = append(env, "GO111MODULE=on", "GOPROXY=https://goproxy.cn,direct")
|
||||
cmd.Env = env
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user