diff --git a/tools/goctl/rpc/cli/cli.go b/tools/goctl/rpc/cli/cli.go index 762c57a12e57..490b1e1f7c8d 100644 --- a/tools/goctl/rpc/cli/cli.go +++ b/tools/goctl/rpc/cli/cli.go @@ -46,6 +46,8 @@ var ( VarBoolMultiple bool // VarBoolClient describes whether to generate rpc client VarBoolClient bool + // VarBoolPb describes whether to generate pb + VarBoolPb bool ) // RPCNew is to generate rpc greet service, this greet service can speed @@ -91,6 +93,7 @@ func RPCNew(_ *cobra.Command, args []string) error { ctx.Output = filepath.Dir(src) ctx.ProtocCmd = fmt.Sprintf("protoc -I=%s %s --go_out=%s --go-grpc_out=%s", filepath.Dir(src), filepath.Base(src), filepath.Dir(src), filepath.Dir(src)) ctx.IsGenClient = VarBoolClient + ctx.IsGenPb = true grpcOptList := VarStringSliceGoGRPCOpt if len(grpcOptList) > 0 { diff --git a/tools/goctl/rpc/cli/zrpc.go b/tools/goctl/rpc/cli/zrpc.go index 558d97786dad..06a0933bb72a 100644 --- a/tools/goctl/rpc/cli/zrpc.go +++ b/tools/goctl/rpc/cli/zrpc.go @@ -103,6 +103,7 @@ func ZRPC(_ *cobra.Command, args []string) error { ctx.Output = zrpcOut ctx.ProtocCmd = strings.Join(protocArgs, " ") ctx.IsGenClient = VarBoolClient + ctx.IsGenPb = VarBoolPb g := generator.NewGenerator(style, verbose) return g.Generate(&ctx) } diff --git a/tools/goctl/rpc/cmd.go b/tools/goctl/rpc/cmd.go index 0bb69c3af1e8..4e8d3204c4fd 100644 --- a/tools/goctl/rpc/cmd.go +++ b/tools/goctl/rpc/cmd.go @@ -65,6 +65,7 @@ func init() { protocCmdFlags.MarkHidden("plugin") protocCmdFlags.MarkHidden("proto_path") protocCmdFlags.BoolVarPWithDefaultValue(&cli.VarBoolClient, "client", "c", true) + protocCmdFlags.BoolVarPWithDefaultValue(&cli.VarBoolPb, "pb", "p", true) templateCmdFlags.StringVar(&cli.VarStringOutput, "o") templateCmdFlags.StringVar(&cli.VarStringHome, "home") diff --git a/tools/goctl/rpc/generator/gen.go b/tools/goctl/rpc/generator/gen.go index 3140d997c35b..b4db7a3b35e4 100644 --- a/tools/goctl/rpc/generator/gen.go +++ b/tools/goctl/rpc/generator/gen.go @@ -30,6 +30,8 @@ type ZRpcContext struct { Multiple bool // Whether to generate rpc client IsGenClient bool + //Whether to generate pb file + IsGenPb bool } // Generate generates a rpc service, through the proto file, @@ -72,9 +74,11 @@ func (g *Generator) Generate(zctx *ZRpcContext) error { return err } - err = g.GenPb(dirCtx, zctx) - if err != nil { - return err + if zctx.IsGenPb { + err = g.GenPb(dirCtx, zctx) + if err != nil { + return err + } } err = g.GenConfig(dirCtx, proto, g.cfg) diff --git a/tools/goctl/rpc/generator/mkdir.go b/tools/goctl/rpc/generator/mkdir.go index 163f904a9f62..284d62391b3f 100644 --- a/tools/goctl/rpc/generator/mkdir.go +++ b/tools/goctl/rpc/generator/mkdir.go @@ -69,10 +69,6 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto, conf *conf.Config, c *ZR svcDir := filepath.Join(internalDir, "svc") pbDir := filepath.Join(ctx.WorkDir, proto.GoPackage) protoGoDir := pbDir - if c != nil { - pbDir = c.ProtoGenGrpcDir - protoGoDir = c.ProtoGenGoDir - } getChildPackage := func(parent, childPath string) (string, error) { child := strings.TrimPrefix(childPath, parent)