httprouter
httprouter copied to clipboard
Dump all registered routes
Hi,
Is there a way to dump list of all registered routes and methods?
Thanks
POST /api/v1/users
GET /api/v2/comments/:id
DELETE /api/v2/comments/:id
...
Consider wrapping the router, and then replacing it, but using RLock when serving.
type MyRouter struct {
router *router.Router
lock sync.RWMutex
}
func (r *MyRouter) ReplaceRouter(router *router.Router) {
r.lock.Lock()
defer r.lock.Unlock()
r.router = router
}
func (r *MyRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
r.lock.RLock()
defer r.lock.RUnlock()
r.router.ServeHTTP(w, req)
}
@BubbaJoe I think he was asking for a way to output the list, not drop the routes.
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。