'In Go gin framework , how to get all url that I have registered in the router

I’m programming the role based access control with casbin. However ,the police need me to provide urls that the role has. The “v1” column in the table, see the picture. I wondered can I get all urls that I registered in router. So that I don’t need to add by my hand.



Solution 1:[1]

You can use Routes which would return slice of RoutesInfo through which you can get all the register route path plus additional informaiton.

RoutesInfo will contain below struct from which required information can be retrieved.

type RouteInfo struct {
    Method      string
    Path        string
    Handler     string
    HandlerFunc HandlerFunc
}
r := gin.Default()
r.Routes()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chandan