19

I am working on a restful service in golang using chi. I am trying to create a route as below

r.Mount("/api/dest", router.NewDestRouter(chi.NewRouter(), destSrv).InitRoutes())

func (dr *DestRouter) InitRoutes() http.Handler {
    dr.router.Post("/{number}/product?version={v}", handlers.HandleProduct(dr.dest))
    return dr.router
}

But I try to hit this endpoint via post man I get a 404 not found

http://localhost:8345/api/dest/1235abc/product?version=1

May I know the issue here?

1
  • 16
    Just a guess as I am not a chi user, but I assume it doesn't match against query parameters, so leave it out when registering the handler and use r.URL.Query().Get("version") to retrieve the value. Commented Aug 20, 2018 at 15:32

2 Answers 2

31

As @mkopriva mentioned, simply use r.URL.Query().Get("version") to get the query parameter.

Sign up to request clarification or add additional context in comments.

Comments

0

Met this issue, found status 404, for your situation, only go with /{number}/product, do not need to add the content ?version={v}, chi only match with the path, and then use r.URL.Query().Get("version") to get the query parameters, it will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.