Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang Chi router with query params not working

Tags:

rest

go

go-chi

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?

like image 588
DoIt Avatar asked Aug 20 '18 14:08

DoIt


Video Answer


1 Answers

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

like image 128
User1 Avatar answered Oct 05 '22 09:10

User1