mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
add whether to generate rpc client option (#3361)
Co-authored-by: admin <admin@admindeMacBook-Pro.local>
This commit is contained in:
parent
b176d5d434
commit
f5f5261556
1
tools/goctl/.gitignore
vendored
1
tools/goctl/.gitignore
vendored
@ -1 +1,2 @@
|
||||
.vscode
|
||||
.idea
|
@ -226,7 +226,8 @@
|
||||
"home": "{{.global.home}}",
|
||||
"remote": "{{.global.remote}}",
|
||||
"branch": "{{.global.branch}}",
|
||||
"verbose": "Enable log output"
|
||||
"verbose": "Enable log output",
|
||||
"client": "Whether to generate rpc client"
|
||||
},
|
||||
"template": {
|
||||
"short": "Generate proto template",
|
||||
@ -243,7 +244,8 @@
|
||||
"home": "{{.global.home}}",
|
||||
"remote": "{{.global.remote}}",
|
||||
"branch": "{{.global.branch}}",
|
||||
"verbose": "Enable log output"
|
||||
"verbose": "Enable log output",
|
||||
"client": "Whether to generate rpc client"
|
||||
}
|
||||
},
|
||||
"template": {
|
||||
|
@ -44,6 +44,8 @@ var (
|
||||
VarBoolVerbose bool
|
||||
// VarBoolMultiple describes whether support generating multiple rpc services or not.
|
||||
VarBoolMultiple bool
|
||||
// VarBoolClient describes whether to generate rpc client
|
||||
VarBoolClient bool
|
||||
)
|
||||
|
||||
// RPCNew is to generate rpc greet service, this greet service can speed
|
||||
@ -88,6 +90,7 @@ func RPCNew(_ *cobra.Command, args []string) 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))
|
||||
ctx.IsGenClient = VarBoolClient
|
||||
|
||||
grpcOptList := VarStringSliceGoGRPCOpt
|
||||
if len(grpcOptList) > 0 {
|
||||
|
@ -102,6 +102,7 @@ func ZRPC(_ *cobra.Command, args []string) error {
|
||||
ctx.IsGooglePlugin = isGooglePlugin
|
||||
ctx.Output = zrpcOut
|
||||
ctx.ProtocCmd = strings.Join(protocArgs, " ")
|
||||
ctx.IsGenClient = VarBoolClient
|
||||
g := generator.NewGenerator(style, verbose)
|
||||
return g.Generate(&ctx)
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ func init() {
|
||||
newCmdFlags.BoolVarP(&cli.VarBoolVerbose, "verbose", "v")
|
||||
newCmdFlags.MarkHidden("go_opt")
|
||||
newCmdFlags.MarkHidden("go-grpc_opt")
|
||||
newCmdFlags.BoolVarPWithDefaultValue(&cli.VarBoolClient, "client", "c", true)
|
||||
|
||||
protocCmdFlags.BoolVarP(&cli.VarBoolMultiple, "multiple", "m")
|
||||
protocCmdFlags.StringSliceVar(&cli.VarStringSliceGoOut, "go_out")
|
||||
@ -63,6 +64,7 @@ func init() {
|
||||
protocCmdFlags.MarkHidden("go-grpc_opt")
|
||||
protocCmdFlags.MarkHidden("plugin")
|
||||
protocCmdFlags.MarkHidden("proto_path")
|
||||
protocCmdFlags.BoolVarPWithDefaultValue(&cli.VarBoolClient, "client", "c", true)
|
||||
|
||||
templateCmdFlags.StringVar(&cli.VarStringOutput, "o")
|
||||
templateCmdFlags.StringVar(&cli.VarStringHome, "home")
|
||||
|
@ -28,6 +28,8 @@ type ZRpcContext struct {
|
||||
Output string
|
||||
// Multiple is the flag to indicate whether the proto file is generated in multiple mode.
|
||||
Multiple bool
|
||||
// Whether to generate rpc client
|
||||
IsGenClient bool
|
||||
}
|
||||
|
||||
// Generate generates a rpc service, through the proto file,
|
||||
@ -100,7 +102,9 @@ func (g *Generator) Generate(zctx *ZRpcContext) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if zctx.IsGenClient {
|
||||
err = g.GenCall(dirCtx, proto, g.cfg, zctx)
|
||||
}
|
||||
|
||||
console.NewColorConsole().MarkDone()
|
||||
|
||||
|
@ -87,6 +87,7 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto, conf *conf.Config, c *ZR
|
||||
return filepath.ToSlash(pkg), nil
|
||||
}
|
||||
|
||||
var callClientDir string
|
||||
if !c.Multiple {
|
||||
callDir := filepath.Join(ctx.WorkDir,
|
||||
strings.ToLower(stringx.From(proto.Service[0].Name).ToCamel()))
|
||||
@ -98,23 +99,18 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto, conf *conf.Config, c *ZR
|
||||
}
|
||||
callDir = filepath.Join(ctx.WorkDir, clientDir)
|
||||
}
|
||||
inner[call] = Dir{
|
||||
Filename: callDir,
|
||||
Package: filepath.ToSlash(filepath.Join(ctx.Path,
|
||||
strings.TrimPrefix(callDir, ctx.Dir))),
|
||||
Base: filepath.Base(callDir),
|
||||
GetChildPackage: func(childPath string) (string, error) {
|
||||
return getChildPackage(callDir, childPath)
|
||||
},
|
||||
}
|
||||
callClientDir = callDir
|
||||
} else {
|
||||
callClientDir = clientDir
|
||||
}
|
||||
if c.IsGenClient {
|
||||
inner[call] = Dir{
|
||||
Filename: clientDir,
|
||||
Filename: callClientDir,
|
||||
Package: filepath.ToSlash(filepath.Join(ctx.Path,
|
||||
strings.TrimPrefix(clientDir, ctx.Dir))),
|
||||
Base: filepath.Base(clientDir),
|
||||
strings.TrimPrefix(callClientDir, ctx.Dir))),
|
||||
Base: filepath.Base(callClientDir),
|
||||
GetChildPackage: func(childPath string) (string, error) {
|
||||
return getChildPackage(clientDir, childPath)
|
||||
return getChildPackage(callClientDir, childPath)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user