reset link goctl (#1232)

This commit is contained in:
anqiansong
2021-11-13 18:39:07 +08:00
committed by GitHub
parent 57d2f22c24
commit 0cb86c6990
7 changed files with 40 additions and 93 deletions

View File

@@ -4,9 +4,11 @@ import (
"errors"
"fmt"
"path/filepath"
"runtime"
"github.com/tal-tech/go-zero/tools/goctl/rpc/generator"
"github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/tal-tech/go-zero/tools/goctl/util/env"
"github.com/urfave/cli"
)
@@ -14,6 +16,10 @@ import (
// you can specify a target folder for code generation, when the proto file has import, you can specify
// the import search directory through the proto_path command, for specific usage, please refer to protoc -h
func RPC(c *cli.Context) error {
if err := prepare(); err != nil {
return err
}
src := c.String("src")
out := c.String("dir")
style := c.String("style")
@@ -41,6 +47,22 @@ func RPC(c *cli.Context) error {
return g.Generate(src, out, protoImportPath, goOptions...)
}
func prepare() error {
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
}
if _, err := env.LookUpProtoc(); err != nil {
return err
}
if _, err := env.LookUpProtocGenGo(); err != nil {
return err
}
return nil
}
// RPCNew is to generate rpc greet service, this greet service can speed
// up your understanding of the zrpc service structure
func RPCNew(c *cli.Context) error {