httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

Dump all registered routes

Open bentcoder opened this issue 3 years ago • 3 comments

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
...

bentcoder avatar Oct 21 '22 18:10 bentcoder

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 avatar Dec 07 '22 00:12 bubbajoe

@BubbaJoe I think he was asking for a way to output the list, not drop the routes.

Harnish avatar Jan 09 '23 20:01 Harnish

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

letmestudy avatar Jan 09 '23 20:01 letmestudy