Feature rpc protoc (#1251)
* code generation by protoc * generate pb by protoc direct * support: grpc code generation by protoc directly * format code * check --go_out & --go-grpc_out * fix typo * Update version * fix typo * optimize: remove deprecated unit test * format code Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package generator
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -16,7 +17,12 @@ const googleProtocGenGoErr = `--go_out: protoc-gen-go: plugins are not supported
|
||||
|
||||
// GenPb generates the pb.go file, which is a layer of packaging for protoc to generate gprc,
|
||||
// but the commands and flags in protoc are not completely joined in goctl. At present, proto_path(-I) is introduced
|
||||
func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, _ *conf.Config, goOptions ...string) error {
|
||||
func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, _ *conf.Config, c *ZRpcContext, goOptions ...string) error {
|
||||
if c != nil {
|
||||
return g.genPbDirect(c)
|
||||
}
|
||||
|
||||
// deprecated: use genPbDirect instead.
|
||||
dir := ctx.GetPb()
|
||||
cw := new(bytes.Buffer)
|
||||
directory, base := filepath.Split(proto.Src)
|
||||
@@ -103,3 +109,14 @@ go get -u github.com/golang/protobuf/protoc-gen-go`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *DefaultGenerator) genPbDirect(c *ZRpcContext) error {
|
||||
g.log.Debug(c.ProtocCmd)
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = execx.Run(c.ProtocCmd, pwd)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user