Feature: Include router option that prevents over writing routes
- Dominant language
- Go
- Stars
- 22.8k
- Forks
- 1.2k
- Avg merge
- 5h 17m
- Merged PRs (30d)
- 10
Description
I discovered a scenario where you can create two handlers that handle the same pattern but the second one "overwrites" the first one.
The expected behavior would be to panic. Because the pattern `GET /things` being attempted to be added twice
```go
baseRouter := chi.NewRouter()
baseRouter.Get("/things", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("things"))
})
things := chi.NewRouter()
things.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("other things"))
})
baseRouter.Mount("/things", things) //should panic
```
The example below I would not expect to panic because there are no overlapping URL patterns. The are `GET /things` and `GET /things/other`
```go
baseRouter := chi.NewRouter()
baseRouter.Get("/things", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("things"))
})
things := chi.NewRouter()
things.Get("/other", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("other things"))
})
baseRouter.Mount("/things", things) //should not panic
```
For a `GET /things` the response will be `other things`
Contributor guide
Assessment
This issue has not been assessed yet.