diff --git a/tools/goctl/goctl.go b/tools/goctl/goctl.go index 8a8f9269..445dfc60 100644 --- a/tools/goctl/goctl.go +++ b/tools/goctl/goctl.go @@ -538,6 +538,14 @@ var commands = []cli.Command{ Usage: `generate rpc demo service`, UsageText: "example: goctl rpc new [options] service-name", Flags: []cli.Flag{ + cli.StringSliceFlag{ + Name: "go_opt", + Hidden: true, + }, + cli.StringSliceFlag{ + Name: "go-grpc_opt", + Hidden: true, + }, cli.StringFlag{ Name: "style", Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]", diff --git a/tools/goctl/rpc/cli/cli.go b/tools/goctl/rpc/cli/cli.go index 236811ad..f625f29b 100644 --- a/tools/goctl/rpc/cli/cli.go +++ b/tools/goctl/rpc/cli/cli.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "path/filepath" + "strings" "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/rpc/generator" @@ -58,6 +59,17 @@ func RPCNew(c *cli.Context) error { ctx.IsGooglePlugin = true 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)) + + grpcOptList := c.StringSlice("go-grpc_opt") + if len(grpcOptList) > 0 { + ctx.ProtocCmd += " --go-grpc_opt=" + strings.Join(grpcOptList, ",") + } + + goOptList := c.StringSlice("go_opt") + if len(goOptList) > 0 { + ctx.ProtocCmd += " --go_opt=" + strings.Join(goOptList, ",") + } + g := generator.NewGenerator(style, verbose) return g.Generate(&ctx) }