Merge pull request #1113 from prometheus/router

Switch to common/route package
This commit is contained in:
Fabian Reinartz 2015-09-24 17:15:40 +02:00
commit 656b2e2109
9 changed files with 16 additions and 34 deletions

View file

@ -1,27 +0,0 @@
package route
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestRedirect(t *testing.T) {
router := New().WithPrefix("/test/prefix")
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil)
if err != nil {
t.Fatalf("Error building test request: %s", err)
}
router.Redirect(w, r, "/some/endpoint", http.StatusFound)
if w.Code != http.StatusFound {
t.Fatalf("Unexpected redirect status code: got %d, want %d", w.Code, http.StatusFound)
}
want := "/test/prefix/some/endpoint"
got := w.Header()["Location"][0]
if want != got {
t.Fatalf("Unexpected redirect location: got %s, want %s", got, want)
}
}

View file

@ -80,6 +80,11 @@ func (r *Router) Del(path string, h http.HandlerFunc) {
r.rtr.DELETE(r.prefix+path, handle(h))
}
// Put registers a new PUT route.
func (r *Router) Put(path string, h http.HandlerFunc) {
r.rtr.PUT(r.prefix+path, handle(h))
}
// Post registers a new POST route.
func (r *Router) Post(path string, h http.HandlerFunc) {
r.rtr.POST(r.prefix+path, handle(h))

5
vendor/vendor.json vendored
View file

@ -82,6 +82,11 @@
"revision": "c33395bbc758c8d25735ec7036d66b342084ae35",
"revisionTime": "2015-08-25T14:37:19+02:00"
},
{
"path": "github.com/prometheus/common/route",
"revision": "ffd5d0f2976124c788687ec2ac194f5479e1f9c2",
"revisionTime": "2015-09-24T17:06:36+02:00"
},
{
"path": "github.com/prometheus/log",
"revision": "439e5db48fbb50ebbaf2c816030473a62f505f55",

View file

@ -18,11 +18,11 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/route"
)
// API manages the /api HTTP endpoint.

View file

@ -22,10 +22,10 @@ import (
"time"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/util/route"
)
// This is a bit annoying. On one hand, we have to choose a current timestamp

View file

@ -11,13 +11,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"golang.org/x/net/context"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/route"
"github.com/prometheus/prometheus/util/strutil"
)

View file

@ -13,10 +13,10 @@ import (
"time"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"golang.org/x/net/context"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/util/route"
)
func TestEndpoints(t *testing.T) {

View file

@ -8,9 +8,8 @@ import (
"net/http"
"strings"
"github.com/prometheus/common/route"
"github.com/prometheus/log"
"github.com/prometheus/prometheus/util/route"
)
// Sub-directories for templates and static content.

View file

@ -33,6 +33,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"github.com/prometheus/log"
"github.com/prometheus/prometheus/config"
@ -42,7 +43,6 @@ import (
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/template"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/route"
"github.com/prometheus/prometheus/version"
"github.com/prometheus/prometheus/web/api/legacy"
"github.com/prometheus/prometheus/web/api/v1"