Create a symbol link file named protoc-gen-goctl from goctl (#1076)

This commit is contained in:
anqiansong
2021-09-21 23:13:31 +08:00
committed by GitHub
parent 06e114e5a3
commit e8a340c1c0
10 changed files with 135 additions and 83 deletions

View File

@@ -1,9 +1,11 @@
package generator
import (
"os/exec"
"fmt"
"runtime"
"github.com/tal-tech/go-zero/tools/goctl/util/console"
"github.com/tal-tech/go-zero/tools/goctl/util/env"
)
// DefaultGenerator defines the environment needs of rpc service generation
@@ -25,17 +27,24 @@ func NewDefaultGenerator() Generator {
// Prepare provides environment detection generated by rpc service,
// including go environment, protoc, whether protoc-gen-go is installed or not
func (g *DefaultGenerator) Prepare() error {
_, err := exec.LookPath("go")
if err != nil {
if !env.CanExec() {
return fmt.Errorf("%s: can not start new processes using os.StartProcess or exec.Command", runtime.GOOS)
}
if _, err := env.LookUpGo(); err != nil {
return err
}
_, err = exec.LookPath("protoc")
if err != nil {
if _, err := env.LookUpProtoc(); err != nil {
return err
}
_, err = exec.LookPath("protoc-gen-go")
_, err := env.LookUpProtocGenGoctl()
if err == nil {
return nil
}
g.log.Warning("%+v", err)
_, err = env.LookUpProtocGenGo()
return err
}