Search code examples
goroutesurl-routinggo-chi

How to serve "/something" and "/something/" both on Golang(go-chi) router?


I am using go-chi router for my application but I am unable to serve "/something" and "/something/" both with one route, if I set my route as "/something"

r := chi.NewRouter()
r.Get("/something", func(writer http.ResponseWriter, request *http.Request) {
    writer.Write([]byte("just for test"))
})

and then request "/something/" its give me 404 page not found error.Is there any way to serve both case with one route?


Solution

  • use middleware StripSlashes, that change path "/something/" to "/something"