echox icon indicating copy to clipboard operation
echox copied to clipboard

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

Open pafuent opened this issue 4 years ago • 1 comments

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

pafuent avatar Dec 15 '20 04:12 pafuent

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

sunecko avatar Nov 18 '23 16:11 sunecko