go-zoo/bone

Support more than one path variable

Closed this issue · 2 comments

It would be useful if we could define multiple path variables, such as /bands/:band/musicians/:musician. However the bone router only works with exactly one variable. The following test does't pass as it would on zeus or gorilla, two of the other routers referred to in the bone README:

func TestMultipleRoutingVariables(t *testing.T) {
    var (
        expected1 = "variable1"
        expected2 = "variable2"
        got1      string
        got2      string
        mux       = New()
        w         = httptest.NewRecorder()
    )
    mux.Get("/:var1/:var2", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        got1 = GetValue(r, "var1")
        got2 = GetValue(r, "var2")
    }))

    r, err := http.NewRequest("GET", fmt.Sprintf("/%s/%s", expected1, expected2), nil)
    if err != nil {
        t.Fatal(err)
    }
    mux.ServeHTTP(w, r)

    if got1 != expected1 {
        t.Fatalf("expected %s, got %s", expected1, got1)
    }

    if got2 != expected2 {
        t.Fatalf("expected %s, got %s", expected2, got2)
    }
}

Done ! :)

Awesome thanks! 🍻