labstack / echox

Echo cookbook and website
https://echo.labstack.com
MIT License
408 stars 285 forks source link

Document how to bind multiple instances of the same query param to a slice #170

Open pafuent opened 3 years ago

pafuent commented 3 years ago

Add documentation about how to bind multiple instances of the same query parameter to a slice. Use this UT as a reference (if it is possible make a more real example than this :wink:)

func TestBindSlices(t *testing.T) {
    e := New()
    req := httptest.NewRequest(GET, "/?str=foo&str=bar&str=foobar", nil)
    rec := httptest.NewRecorder()
    c := e.NewContext(req, rec)
    result := struct {
        Str []string `query:"str"`
    }{}
    err := c.Bind(&result)
    if assert.NoError(t, err) {
        assert.Equal(t, []string{"foo", "bar", "foobar"}, result.Str)
    }
}

Binding documentation is in https://github.com/labstack/echox/blob/master/website/content/guide/request.md

sunecko commented 9 months ago

I can take care of this, this will be my first contribution