feature: file namestyle (#223)

* add api filename style

* new feature: config.yaml

* optimize

* optimize logic generation

* check hanlder valid

* optimize

* reactor naming style

* optimize

* optimize test

* optimize gen middleware

* format

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
Co-authored-by: kim <xutao@xiaoheiban.cn>
This commit is contained in:
kingxt
2020-11-24 15:11:18 +08:00
committed by GitHub
parent 702e8d79ce
commit b9ac51b6c3
40 changed files with 896 additions and 296 deletions

View File

@@ -3,6 +3,7 @@ package generator
import (
"path/filepath"
conf "github.com/tal-tech/go-zero/tools/goctl/config"
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
"github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/tal-tech/go-zero/tools/goctl/util/console"
@@ -10,18 +11,22 @@ import (
)
type RpcGenerator struct {
g Generator
style NamingStyle
g Generator
cfg *conf.Config
}
func NewDefaultRpcGenerator(style NamingStyle) *RpcGenerator {
return NewRpcGenerator(NewDefaultGenerator(), style)
func NewDefaultRpcGenerator(style string) (*RpcGenerator, error) {
cfg, err := conf.NewConfig(style)
if err != nil {
return nil, err
}
return NewRpcGenerator(NewDefaultGenerator(), cfg), nil
}
func NewRpcGenerator(g Generator, style NamingStyle) *RpcGenerator {
func NewRpcGenerator(g Generator, cfg *conf.Config) *RpcGenerator {
return &RpcGenerator{
g: g,
style: style,
g: g,
cfg: cfg,
}
}
@@ -57,42 +62,42 @@ func (g *RpcGenerator) Generate(src, target string, protoImportPath []string) er
return err
}
err = g.g.GenEtc(dirCtx, proto, g.style)
err = g.g.GenEtc(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenPb(dirCtx, protoImportPath, proto, g.style)
err = g.g.GenPb(dirCtx, protoImportPath, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenConfig(dirCtx, proto, g.style)
err = g.g.GenConfig(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenSvc(dirCtx, proto, g.style)
err = g.g.GenSvc(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenLogic(dirCtx, proto, g.style)
err = g.g.GenLogic(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenServer(dirCtx, proto, g.style)
err = g.g.GenServer(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenMain(dirCtx, proto, g.style)
err = g.g.GenMain(dirCtx, proto, g.cfg)
if err != nil {
return err
}
err = g.g.GenCall(dirCtx, proto, g.style)
err = g.g.GenCall(dirCtx, proto, g.cfg)
console.NewColorConsole().MarkDone()