generate endpoint metadata only for http server #74
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)
|
||||||
|
5
util.go
5
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"))
|
||||||
|
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("}")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user