From b7b731fc79056102e355cddff9e2d60dc29563ce Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 2 Apr 2020 12:13:04 +0300 Subject: [PATCH] api/handler/rpc: binary streaming support (#1466) * api/handler/rpc: binary streaming support Signed-off-by: Vasiliy Tolstov * fixup Signed-off-by: Vasiliy Tolstov * fix Signed-off-by: Vasiliy Tolstov * fix sec webscoekt protol Signed-off-by: Vasiliy Tolstov --- static.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/static.go b/static.go index 3cf3beb..3c2c25d 100644 --- a/static.go +++ b/static.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/v2/api/router" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" ) type endpoint struct { @@ -163,13 +164,23 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { // hack for stream endpoint if ep.apiep.Stream { - for _, svc := range services { + svcs := registry.Copy(services) + for _, svc := range svcs { + if len(svc.Endpoints) == 0 { + e := ®istry.Endpoint{} + e.Name = strings.Join(epf[1:], ".") + e.Metadata = make(map[string]string) + e.Metadata["stream"] = "true" + svc.Endpoints = append(svc.Endpoints, e) + } for _, e := range svc.Endpoints { e.Name = strings.Join(epf[1:], ".") e.Metadata = make(map[string]string) e.Metadata["stream"] = "true" } } + + services = svcs } svc := &api.Service{ @@ -180,6 +191,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { Host: ep.apiep.Host, Method: ep.apiep.Method, Path: ep.apiep.Path, + Stream: ep.apiep.Stream, }, Services: services, }