diff --git a/tools/goctl/rpc/generator/genmain.go b/tools/goctl/rpc/generator/genmain.go index 02381538..e0d0849a 100644 --- a/tools/goctl/rpc/generator/genmain.go +++ b/tools/goctl/rpc/generator/genmain.go @@ -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, }) } diff --git a/tools/goctl/rpc/generator/genserver.go b/tools/goctl/rpc/generator/genserver.go index 04c816bf..1ead7ef6 100644 --- a/tools/goctl/rpc/generator/genserver.go +++ b/tools/goctl/rpc/generator/genserver.go @@ -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), diff --git a/tools/goctl/rpc/generator/main.tpl b/tools/goctl/rpc/generator/main.tpl index 58cb6760..566ad82b 100644 --- a/tools/goctl/rpc/generator/main.tpl +++ b/tools/goctl/rpc/generator/main.tpl @@ -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)