From 4f79072fd1e67b1626f6b2d3e8a0428fd9494154 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 2 Oct 2016 23:04:03 +0200 Subject: [PATCH] Update common/route vendoring for contextFn errors --- vendor/github.com/prometheus/common/route/route.go | 14 ++++++++++---- vendor/vendor.json | 4 ++-- web/web.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vendor/github.com/prometheus/common/route/route.go b/vendor/github.com/prometheus/common/route/route.go index ab5b8ed63..930b52d4f 100644 --- a/vendor/github.com/prometheus/common/route/route.go +++ b/vendor/github.com/prometheus/common/route/route.go @@ -1,6 +1,7 @@ package route import ( + "fmt" "net/http" "sync" @@ -32,7 +33,7 @@ func WithParam(ctx context.Context, p, v string) context.Context { return context.WithValue(ctx, param(p), v) } -type contextFn func(r *http.Request) context.Context +type contextFn func(r *http.Request) (context.Context, error) // Router wraps httprouter.Router and adds support for prefixed sub-routers // and per-request context injections. @@ -45,8 +46,8 @@ type Router struct { // New returns a new Router. func New(ctxFn contextFn) *Router { if ctxFn == nil { - ctxFn = func(r *http.Request) context.Context { - return context.Background() + ctxFn = func(r *http.Request) (context.Context, error) { + return context.Background(), nil } } return &Router{ @@ -63,7 +64,12 @@ func (r *Router) WithPrefix(prefix string) *Router { // handle turns a HandlerFunc into an httprouter.Handle. func (r *Router) handle(h http.HandlerFunc) httprouter.Handle { return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) { - ctx, cancel := context.WithCancel(r.ctxFn(req)) + reqCtx, err := r.ctxFn(req) + if err != nil { + http.Error(w, fmt.Sprintf("Error creating request context: %v", err), http.StatusBadRequest) + return + } + ctx, cancel := context.WithCancel(reqCtx) defer cancel() for _, p := range params { diff --git a/vendor/vendor.json b/vendor/vendor.json index 1077dfd67..65708c19d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -211,8 +211,8 @@ { "checksumSHA1": "CKVJRc1NREmfoAWQLHxqWQlvxo0=", "path": "github.com/prometheus/common/route", - "revision": "ee21c31a8cbad2a29cce94a8c53855e1dab92bf7", - "revisionTime": "2016-09-21T02:27:24+02:00" + "revision": "a85e6c850a142b95b63f9dd0ffd9645e5e437da7", + "revisionTime": "2016-10-02T22:56:21+02:00" }, { "checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=", diff --git a/web/web.go b/web/web.go index f2296fbb8..314dae06f 100644 --- a/web/web.go +++ b/web/web.go @@ -120,8 +120,8 @@ type Options struct { // New initializes a new web Handler. func New(o *Options) *Handler { - router := route.New(func(r *http.Request) context.Context { - return o.Context + router := route.New(func(r *http.Request) (context.Context, error) { + return o.Context, nil }) h := &Handler{