Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a flag to whether to generate pb file #4079

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/goctl/rpc/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/rpc/cli/zrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/rpc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 7 additions & 3 deletions tools/goctl/rpc/generator/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions tools/goctl/rpc/generator/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down