update micro to v3.1.1

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-16 01:24:38 +03:00
parent b9ccb43243
commit 637dcb5cc1
3 changed files with 20 additions and 20 deletions

4
go.mod
View File

@ -1,5 +1,5 @@
module github.com/unistack-org/micro-api-router-registry module github.com/unistack-org/micro-api-router-registry/v3
go 1.15 go 1.15
require github.com/unistack-org/micro/v3 v3.0.2-0.20210109225421-8930c3fbb748 require github.com/unistack-org/micro/v3 v3.1.1

4
go.sum
View File

@ -221,8 +221,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY=
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
github.com/unistack-org/micro/v3 v3.0.2-0.20210109225421-8930c3fbb748 h1:tPXIO1QFi2DxPv8nsSACNKsydmToqHZ4x0xIZMvX9es= github.com/unistack-org/micro/v3 v3.1.1 h1:kWL0BVzUBdotjfDbl1qL9lNYmZqvebQWPNCyqrjUSAk=
github.com/unistack-org/micro/v3 v3.0.2-0.20210109225421-8930c3fbb748/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc= github.com/unistack-org/micro/v3 v3.1.1/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

View File

@ -54,7 +54,7 @@ func (r *registryRouter) refresh() {
if err != nil { if err != nil {
attempts++ attempts++
if logger.V(logger.ErrorLevel) { if logger.V(logger.ErrorLevel) {
logger.Errorf("unable to list services: %v", err) logger.Errorf(r.opts.Context, "unable to list services: %v", err)
} }
time.Sleep(time.Duration(attempts) * time.Second) time.Sleep(time.Duration(attempts) * time.Second)
continue continue
@ -67,7 +67,7 @@ func (r *registryRouter) refresh() {
service, err := r.opts.Registry.GetService(r.opts.Context, s.Name) service, err := r.opts.Registry.GetService(r.opts.Context, s.Name)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel) { if logger.V(logger.ErrorLevel) {
logger.Errorf("unable to get service: %v", err) logger.Errorf(r.opts.Context, "unable to get service: %v", err)
} }
continue continue
} }
@ -95,7 +95,7 @@ func (r *registryRouter) process(res *registry.Result) {
service, err := r.opts.Registry.GetService(r.opts.Context, res.Service.Name) service, err := r.opts.Registry.GetService(r.opts.Context, res.Service.Name)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel) { if logger.V(logger.ErrorLevel) {
logger.Errorf("unable to get %v service: %v", res.Service.Name, err) logger.Errorf(r.opts.Context, "unable to get %v service: %v", res.Service.Name, err)
} }
return return
} }
@ -130,7 +130,7 @@ func (r *registryRouter) store(services []*registry.Service) {
// if we got nothing skip // if we got nothing skip
if err := api.Validate(end); err != nil { if err := api.Validate(end); err != nil {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("endpoint validation failed: %v", err) logger.Tracef(r.opts.Context, "endpoint validation failed: %v", err)
} }
continue continue
} }
@ -177,7 +177,7 @@ func (r *registryRouter) store(services []*registry.Service) {
hostreg, err := regexp.CompilePOSIX(h) hostreg, err := regexp.CompilePOSIX(h)
if err != nil { if err != nil {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("endpoint have invalid host regexp: %v", err) logger.Tracef(r.opts.Context, "endpoint have invalid host regexp: %v", err)
} }
continue continue
} }
@ -198,7 +198,7 @@ func (r *registryRouter) store(services []*registry.Service) {
rule, err := util.Parse(p) rule, err := util.Parse(p)
if err != nil && !pcreok { if err != nil && !pcreok {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("endpoint have invalid path pattern: %v", err) logger.Tracef(r.opts.Context, "endpoint have invalid path pattern: %v", err)
} }
continue continue
} else if err != nil && pcreok { } else if err != nil && pcreok {
@ -209,7 +209,7 @@ func (r *registryRouter) store(services []*registry.Service) {
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "")
if err != nil { if err != nil {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("endpoint have invalid path pattern: %v", err) logger.Tracef(r.opts.Context, "endpoint have invalid path pattern: %v", err)
} }
continue continue
} }
@ -234,7 +234,7 @@ func (r *registryRouter) watch() {
if err != nil { if err != nil {
attempts++ attempts++
if logger.V(logger.ErrorLevel) { if logger.V(logger.ErrorLevel) {
logger.Errorf("error watching endpoints: %v", err) logger.Errorf(r.opts.Context, "error watching endpoints: %v", err)
} }
time.Sleep(time.Duration(attempts) * time.Second) time.Sleep(time.Duration(attempts) * time.Second)
continue continue
@ -259,7 +259,7 @@ func (r *registryRouter) watch() {
res, err := w.Next() res, err := w.Next()
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel) { if logger.V(logger.ErrorLevel) {
logger.Errorf("error getting next endpoint: %v", err) logger.Errorf(r.opts.Context, "error getting next endpoint: %v", err)
} }
close(ch) close(ch)
break break
@ -325,7 +325,7 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
continue continue
} }
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api method match %s", req.Method) logger.Tracef(r.opts.Context, "api method match %s", req.Method)
} }
// 2. try host // 2. try host
@ -348,7 +348,7 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
continue continue
} }
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api host match %s", req.URL.Host) logger.Tracef(r.opts.Context, "api host match %s", req.URL.Host)
} }
// 3. try path via google.api path matching // 3. try path via google.api path matching
@ -356,18 +356,18 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
matches, err := pathreg.Match(path, "") matches, err := pathreg.Match(path, "")
if err != nil { if err != nil {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api gpath not match %s != %v", path, pathreg) logger.Tracef(r.opts.Context, "api gpath not match %s != %v", path, pathreg)
} }
continue continue
} }
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api gpath match %s = %v", path, pathreg) logger.Tracef(r.opts.Context, "api gpath match %s = %v", path, pathreg)
} }
pMatch = true pMatch = true
ctx := req.Context() ctx := req.Context()
md, ok := metadata.FromContext(ctx) md, ok := metadata.FromContext(ctx)
if !ok { if !ok {
md = make(metadata.Metadata) md = metadata.New(len(matches) + 1)
} }
for k, v := range matches { for k, v := range matches {
md[fmt.Sprintf("x-api-field-%s", k)] = v md[fmt.Sprintf("x-api-field-%s", k)] = v
@ -382,12 +382,12 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
for _, pathreg := range cep.pcreregs { for _, pathreg := range cep.pcreregs {
if !pathreg.MatchString(req.URL.Path) { if !pathreg.MatchString(req.URL.Path) {
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api pcre path not match %s != %v", path, pathreg) logger.Tracef(r.opts.Context, "api pcre path not match %s != %v", path, pathreg)
} }
continue continue
} }
if logger.V(logger.TraceLevel) { if logger.V(logger.TraceLevel) {
logger.Tracef("api pcre path match %s != %v", path, pathreg) logger.Tracef(r.opts.Context, "api pcre path match %s != %v", path, pathreg)
} }
pMatch = true pMatch = true
break break