generate endpoint metadata only for http server
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
2f9003161b
commit
dbaa0089b6
2
http.go
2
http.go
@ -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
2
rpc.go
@ -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)
|
||||||
|
7
util.go
7
util.go
@ -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"))
|
||||||
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("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
|
||||||
gfile.P("}")
|
gfile.P("}")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user