feat: Support for multiple rpc service generation and rpc grouping (#1972)
* Add group & compatible flag * Add group & compatible flag * Support for multiple rpc service generation and rpc grouping * Support for multiple rpc service generation and rpc grouping * Format code * Format code * Add comments * Fix unit test * Refactor function name * Add example & Update grpc readme * go mod tidy * update mod * update mod
This commit is contained in:
@@ -10,17 +10,27 @@ import (
|
||||
)
|
||||
|
||||
type ZRpcContext struct {
|
||||
Src string
|
||||
ProtocCmd string
|
||||
// Sre is the source file of the proto.
|
||||
Src string
|
||||
// ProtoCmd is the command to generate proto files.
|
||||
ProtocCmd string
|
||||
// ProtoGenGrpcDir is the directory to store the generated proto files.
|
||||
ProtoGenGrpcDir string
|
||||
ProtoGenGoDir string
|
||||
IsGooglePlugin bool
|
||||
GoOutput string
|
||||
GrpcOutput string
|
||||
Output string
|
||||
// ProtoGenGoDir is the directory to store the generated go files.
|
||||
ProtoGenGoDir string
|
||||
// IsGooglePlugin is the flag to indicate whether the proto file is generated by google plugin.
|
||||
IsGooglePlugin bool
|
||||
// GoOutput is the output directory of the generated go files.
|
||||
GoOutput string
|
||||
// GrpcOutput is the output directory of the generated grpc files.
|
||||
GrpcOutput string
|
||||
// Output is the output directory of the generated files.
|
||||
Output string
|
||||
// Multiple is the flag to indicate whether the proto file is generated in multiple mode.
|
||||
Multiple bool
|
||||
}
|
||||
|
||||
// Generate generates an rpc service, through the proto file,
|
||||
// Generate generates a rpc service, through the proto file,
|
||||
// code storage directory, and proto import parameters to control
|
||||
// the source file and target location of the rpc service that needs to be generated
|
||||
func (g *Generator) Generate(zctx *ZRpcContext) error {
|
||||
@@ -45,7 +55,7 @@ func (g *Generator) Generate(zctx *ZRpcContext) error {
|
||||
}
|
||||
|
||||
p := parser.NewDefaultProtoParser()
|
||||
proto, err := p.Parse(zctx.Src)
|
||||
proto, err := p.Parse(zctx.Src, zctx.Multiple)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,22 +85,22 @@ func (g *Generator) Generate(zctx *ZRpcContext) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.GenLogic(dirCtx, proto, g.cfg)
|
||||
err = g.GenLogic(dirCtx, proto, g.cfg, zctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.GenServer(dirCtx, proto, g.cfg)
|
||||
err = g.GenServer(dirCtx, proto, g.cfg, zctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.GenMain(dirCtx, proto, g.cfg)
|
||||
err = g.GenMain(dirCtx, proto, g.cfg, zctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.GenCall(dirCtx, proto, g.cfg)
|
||||
err = g.GenCall(dirCtx, proto, g.cfg, zctx)
|
||||
|
||||
console.NewColorConsole().MarkDone()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user