mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
modify the service name from proto (#230)
This commit is contained in:
parent
3ebb1e0221
commit
2dfecda465
@ -22,7 +22,7 @@ Etcd:
|
||||
|
||||
func (g *defaultGenerator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config) error {
|
||||
dir := ctx.GetEtc()
|
||||
etcFilename, err := format.FileNamingFormat(cfg.NamingFormat, ctx.GetMain().Base)
|
||||
etcFilename, err := format.FileNamingFormat(cfg.NamingFormat, ctx.GetServiceName().Source())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -35,6 +35,6 @@ func (g *defaultGenerator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Conf
|
||||
}
|
||||
|
||||
return util.With("etc").Parse(text).SaveTo(map[string]interface{}{
|
||||
"serviceName": strings.ToLower(stringx.From(ctx.GetMain().Base).ToCamel()),
|
||||
"serviceName": strings.ToLower(stringx.From(ctx.GetServiceName().Source()).ToCamel()),
|
||||
}, fileName, false)
|
||||
}
|
||||
|
@ -48,13 +48,12 @@ func main() {
|
||||
`
|
||||
|
||||
func (g *defaultGenerator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config) error {
|
||||
dir := ctx.GetMain()
|
||||
mainFilename, err := format.FileNamingFormat(cfg.NamingFormat, ctx.GetMain().Base)
|
||||
mainFilename, err := format.FileNamingFormat(cfg.NamingFormat, ctx.GetServiceName().Source())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileName := filepath.Join(dir.Filename, fmt.Sprintf("%v.go", mainFilename))
|
||||
fileName := filepath.Join(ctx.GetMain().Filename, fmt.Sprintf("%v.go", mainFilename))
|
||||
imports := make([]string, 0)
|
||||
pbImport := fmt.Sprintf(`"%v"`, ctx.GetPb().Package)
|
||||
svcImport := fmt.Sprintf(`"%v"`, ctx.GetSvc().Package)
|
||||
@ -69,7 +68,7 @@ func (g *defaultGenerator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf
|
||||
|
||||
return util.With("main").GoFmt(true).Parse(text).SaveTo(map[string]interface{}{
|
||||
"head": head,
|
||||
"serviceName": strings.ToLower(stringx.From(ctx.GetMain().Base).ToCamel()),
|
||||
"serviceName": strings.ToLower(ctx.GetServiceName().ToCamel()),
|
||||
"imports": strings.Join(imports, util.NL),
|
||||
"pkg": proto.PbPackage,
|
||||
"serviceNew": stringx.From(proto.Service.Name).ToCamel(),
|
||||
|
@ -33,6 +33,7 @@ type (
|
||||
GetSvc() Dir
|
||||
GetPb() Dir
|
||||
GetMain() Dir
|
||||
GetServiceName() stringx.String
|
||||
}
|
||||
|
||||
Dir struct {
|
||||
@ -41,7 +42,8 @@ type (
|
||||
Package string
|
||||
}
|
||||
defaultDirContext struct {
|
||||
inner map[string]Dir
|
||||
inner map[string]Dir
|
||||
serviceName stringx.String
|
||||
}
|
||||
)
|
||||
|
||||
@ -110,8 +112,10 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto) (DirContext, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
serviceName := strings.TrimSuffix(proto.Name, filepath.Ext(proto.Name))
|
||||
return &defaultDirContext{
|
||||
inner: inner,
|
||||
inner: inner,
|
||||
serviceName: stringx.From(strings.ReplaceAll(serviceName, "-", "")),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -151,6 +155,10 @@ func (d *defaultDirContext) GetMain() Dir {
|
||||
return d.inner[wd]
|
||||
}
|
||||
|
||||
func (d *defaultDirContext) GetServiceName() stringx.String {
|
||||
return d.serviceName
|
||||
}
|
||||
|
||||
func (d *Dir) Valid() bool {
|
||||
return len(d.Filename) > 0 && len(d.Package) > 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user