Merge pull request 'generate endpoint metadata only for http server' (#74) from fixup into v3

Reviewed-on: #74
This commit is contained in:
Василий Толстов 2023-03-15 01:11:20 +03:00
commit 1bdd68d6ea
3 changed files with 6 additions and 5 deletions

View File

@ -45,7 +45,7 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
if genServer {
generateServiceServer(gfile, service)
g.generateServiceServerMethods(gfile, service)
g.generateServiceRegister(gfile, service)
g.generateServiceRegister(gfile, service, component)
}
}
}

2
rpc.go
View File

@ -43,7 +43,7 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
if genServer {
generateServiceServer(gfile, service)
g.generateServiceServerMethods(gfile, service)
g.generateServiceRegister(gfile, service)
g.generateServiceRegister(gfile, service, component)
}
if component == "grpc" && g.reflection {
g.generateServiceDesc(gfile, file, service)

View File

@ -477,7 +477,7 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
}
}
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service) {
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
serviceName := service.GoName
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
gfile.P("type ", unexport(serviceName), " interface {")
@ -490,8 +490,9 @@ func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, servi
gfile.P("}")
gfile.P("h := &", unexport(serviceName), "Server{sh}")
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
if component == "http" {
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
}
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
gfile.P("}")
}