generate endpoint metadata only for http server #74

Merged
vtolstov merged 1 commits from fixup into v3 2023-03-15 01:11:21 +03:00
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 { if genServer {
generateServiceServer(gfile, service) generateServiceServer(gfile, service)
g.generateServiceServerMethods(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 { if genServer {
generateServiceServer(gfile, service) generateServiceServer(gfile, service)
g.generateServiceServerMethods(gfile, service) g.generateServiceServerMethods(gfile, service)
g.generateServiceRegister(gfile, service) g.generateServiceRegister(gfile, service, component)
} }
if component == "grpc" && g.reflection { if component == "grpc" && g.reflection {
g.generateServiceDesc(gfile, file, service) 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 serviceName := service.GoName
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {") gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
gfile.P("type ", unexport(serviceName), " interface {") gfile.P("type ", unexport(serviceName), " interface {")
@ -490,8 +490,9 @@ func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, servi
gfile.P("}") gfile.P("}")
gfile.P("h := &", unexport(serviceName), "Server{sh}") gfile.P("h := &", unexport(serviceName), "Server{sh}")
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption")) gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
if component == "http" {
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))") gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
}
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))") gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
gfile.P("}") gfile.P("}")
} }