浏览代码

add go-grpc_opt and go_opt for grpc new command (#1769)

Co-authored-by: zhouyy <zhouyy@ickey.cn>
chowyu12 3 年之前
父节点
当前提交
14bf2f33f7
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 8 0
      tools/goctl/goctl.go
  2. 12 0
      tools/goctl/rpc/cli/cli.go

+ 8 - 0
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]",

+ 12 - 0
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)
 }