From 6db825838aa40cdc00eb1b01bb26c4b7bb9e68bb Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Apr 2020 17:50:51 +0300 Subject: [PATCH] api/router/registry: extract path based parameters from url to req (#1530) * api/router/registry: extract path based parameters from url to req * api/handler/rpc: fix empty body request parsing * bundle grpc-gateway util funcs Signed-off-by: Vasiliy Tolstov --- static.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/static.go b/static.go index fd630cc..927969c 100644 --- a/static.go +++ b/static.go @@ -8,20 +8,19 @@ import ( "strings" "sync" - "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule" - "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/api/router/util" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" - util "github.com/micro/go-micro/v2/util/registry" + rutil "github.com/micro/go-micro/v2/util/registry" ) type endpoint struct { apiep *api.Endpoint hostregs []*regexp.Regexp - pathregs []runtime.Pattern + pathregs []util.Pattern } // router is the default router @@ -93,7 +92,7 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { return err } - var pathregs []runtime.Pattern + var pathregs []util.Pattern var hostregs []*regexp.Regexp for _, h := range ep.Host { @@ -108,12 +107,12 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { } for _, p := range ep.Path { - rule, err := httprule.Parse(p) + rule, err := util.Parse(p) if err != nil { return err } tpl := rule.Compile() - pathreg, err := runtime.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") + pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") if err != nil { return err } @@ -164,7 +163,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { // hack for stream endpoint if ep.apiep.Stream { - svcs := util.Copy(services) + svcs := rutil.Copy(services) for _, svc := range svcs { if len(svc.Endpoints) == 0 { e := ®istry.Endpoint{}