feat: Remove command goctl rpc proto (#1665)
* Fix goctl completion expression * Fix code generation error if the pkg of pb/grpc is same to zrpc call client pkg * Remove deprecated comment on action goctl rpc new * Remove zrpc code generation on action goctl rpc proto * Remove zrpc code generation on action goctl rpc proto * Remove Generator interface Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -3,22 +3,12 @@ package generator
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
conf "github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/parser"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/console"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/ctx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
// RPCGenerator defines a generator and configure
|
||||
type RPCGenerator struct {
|
||||
g Generator
|
||||
cfg *conf.Config
|
||||
ctx *ZRpcContext
|
||||
}
|
||||
|
||||
type RPCGeneratorOption func(g *RPCGenerator)
|
||||
|
||||
type ZRpcContext struct {
|
||||
Src string
|
||||
ProtocCmd string
|
||||
@@ -30,38 +20,11 @@ type ZRpcContext struct {
|
||||
Output string
|
||||
}
|
||||
|
||||
// NewDefaultRPCGenerator wraps Generator with configure
|
||||
func NewDefaultRPCGenerator(style string, options ...RPCGeneratorOption) (*RPCGenerator, error) {
|
||||
cfg, err := conf.NewConfig(style)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewRPCGenerator(NewDefaultGenerator(), cfg, options...), nil
|
||||
}
|
||||
|
||||
// NewRPCGenerator creates an instance for RPCGenerator
|
||||
func NewRPCGenerator(g Generator, cfg *conf.Config, options ...RPCGeneratorOption) *RPCGenerator {
|
||||
out := &RPCGenerator{
|
||||
g: g,
|
||||
cfg: cfg,
|
||||
}
|
||||
for _, opt := range options {
|
||||
opt(out)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func WithZRpcContext(c *ZRpcContext) RPCGeneratorOption {
|
||||
return func(g *RPCGenerator) {
|
||||
g.ctx = c
|
||||
}
|
||||
}
|
||||
|
||||
// Generate generates an 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 *RPCGenerator) Generate(src, target string, protoImportPath []string, goOptions ...string) error {
|
||||
abs, err := filepath.Abs(target)
|
||||
func (g *Generator) Generate(zctx *ZRpcContext) error {
|
||||
abs, err := filepath.Abs(zctx.Output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -71,7 +34,7 @@ func (g *RPCGenerator) Generate(src, target string, protoImportPath []string, go
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.Prepare()
|
||||
err = g.Prepare()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -82,52 +45,52 @@ func (g *RPCGenerator) Generate(src, target string, protoImportPath []string, go
|
||||
}
|
||||
|
||||
p := parser.NewDefaultProtoParser()
|
||||
proto, err := p.Parse(src)
|
||||
proto, err := p.Parse(zctx.Src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dirCtx, err := mkdir(projectCtx, proto, g.cfg, g.ctx)
|
||||
dirCtx, err := mkdir(projectCtx, proto, g.cfg, zctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenEtc(dirCtx, proto, g.cfg)
|
||||
err = g.GenEtc(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenPb(dirCtx, protoImportPath, proto, g.cfg, g.ctx, goOptions...)
|
||||
err = g.GenPb(dirCtx, zctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenConfig(dirCtx, proto, g.cfg)
|
||||
err = g.GenConfig(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenSvc(dirCtx, proto, g.cfg)
|
||||
err = g.GenSvc(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenLogic(dirCtx, proto, g.cfg)
|
||||
err = g.GenLogic(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenServer(dirCtx, proto, g.cfg)
|
||||
err = g.GenServer(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenMain(dirCtx, proto, g.cfg)
|
||||
err = g.GenMain(dirCtx, proto, g.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = g.g.GenCall(dirCtx, proto, g.cfg)
|
||||
err = g.GenCall(dirCtx, proto, g.cfg)
|
||||
|
||||
console.NewColorConsole().MarkDone()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user