I regularly have to look up how to create an Echo router context with (a) path parameters and (b) query parameters, so I’m making this post as a cheat sheet for my future self.
Path parameters
Example: /some/random/path/:id
// create your context
ctx := echo.New().NewContext(request, response)
// add your path param
ctx.SetParamNames("id")
ctx.SetParamValues("foo")
Query parameters
Example: /some/random/path?key1=value1&key2=value2
// create your request
request := httptest.NewRequest(http.MethodPost, "/some/random/path", nil)
// get existing query params
query := request.URL.Query()
// add or set new params
query.Add("key1", "value1")
query.Set("key2", "value2")
// encode the query params back to the request
request.URL.RawQuery = query.Encode()
// create your context with the request
ctx := echo.New().NewContext(request, response)