If you are using httprouter package for routing in your Go application and need to test "named" URL path parameters, you can use example below.


handler := your handler

r := httptest.NewRequest(http.MethodGet, "/api/v1/users/:uuid", nil)
w := httptest.NewRecorder()

ctx := r.Context()
ctx = context.WithValue(ctx, httprouter.ParamsKey, httprouter.Params{
{"uuid", "some-uuid"},
r = r.WithContext(ctx)

handler.Handle(w, r)


If you use code below in your handler, you will see that the some-uuid is there.