diff --git a/http.go b/http.go index e854cf1..a9c0335 100644 --- a/http.go +++ b/http.go @@ -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) } } } diff --git a/rpc.go b/rpc.go index 049ecac..2160468 100644 --- a/rpc.go +++ b/rpc.go @@ -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) diff --git a/util.go b/util.go index be68e57..645b7da 100644 --- a/util.go +++ b/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 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("}") }