mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
parent
8c0bb27136
commit
2d3ebb9b62
@ -11,15 +11,17 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
|
||||
)
|
||||
|
||||
//go:embed main.tpl
|
||||
var mainTemplate string
|
||||
|
||||
type MainServiceTemplateData struct {
|
||||
Service string
|
||||
ServerPkg string
|
||||
Pkg string
|
||||
GRPCService string
|
||||
Service string
|
||||
ServerPkg string
|
||||
Pkg string
|
||||
}
|
||||
|
||||
// GenMain generates the main file of the rpc service, which is an rpc service program call entry
|
||||
@ -57,9 +59,10 @@ func (g *Generator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config
|
||||
}
|
||||
imports = append(imports, remoteImport)
|
||||
serviceNames = append(serviceNames, MainServiceTemplateData{
|
||||
Service: parser.CamelCase(e.Name),
|
||||
ServerPkg: serverPkg,
|
||||
Pkg: proto.PbPackage,
|
||||
GRPCService: parser.CamelCase(e.Name),
|
||||
Service: stringx.From(e.Name).ToCamel(),
|
||||
ServerPkg: serverPkg,
|
||||
Pkg: proto.PbPackage,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func (g *Generator) genServerGroup(ctx DirContext, proto parser.Proto, cfg *conf
|
||||
if err = util.With("server").GoFmt(true).Parse(text).SaveTo(map[string]any{
|
||||
"head": head,
|
||||
"unimplementedServer": fmt.Sprintf("%s.Unimplemented%sServer", proto.PbPackage,
|
||||
stringx.From(service.Name).ToCamel()),
|
||||
parser.CamelCase(service.Name)),
|
||||
"server": stringx.From(service.Name).ToCamel(),
|
||||
"imports": strings.Join(imports.KeysStr(), pathx.NL),
|
||||
"funcs": strings.Join(funcList, pathx.NL),
|
||||
@ -143,7 +143,7 @@ func (g *Generator) genServerInCompatibility(ctx DirContext, proto parser.Proto,
|
||||
return util.With("server").GoFmt(true).Parse(text).SaveTo(map[string]any{
|
||||
"head": head,
|
||||
"unimplementedServer": fmt.Sprintf("%s.Unimplemented%sServer", proto.PbPackage,
|
||||
stringx.From(service.Name).ToCamel()),
|
||||
parser.CamelCase(service.Name)),
|
||||
"server": stringx.From(service.Name).ToCamel(),
|
||||
"imports": strings.Join(imports.KeysStr(), pathx.NL),
|
||||
"funcs": strings.Join(funcList, pathx.NL),
|
||||
|
@ -23,7 +23,7 @@ func main() {
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
{{range .serviceNames}} {{.Pkg}}.Register{{.Service}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx))
|
||||
{{range .serviceNames}} {{.Pkg}}.Register{{.GRPCService}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx))
|
||||
{{end}}
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
|
Loading…
Reference in New Issue
Block a user