diff options
author | Wim <wim@42.be> | 2023-01-28 22:57:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 22:57:53 +0100 |
commit | 880586bac42817ffcfea5d9f746f503fa29915b8 (patch) | |
tree | a89374cba6f88975f12316ec8d1b8aa1d4c6ba79 /vendor/github.com/labstack/echo/v4/router.go | |
parent | eac2a8c8dc831f946970d327e2a80b26b0684255 (diff) | |
download | matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.gz matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.bz2 matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.zip |
Update dependencies (#1951)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/router.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/router.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/v4/router.go b/vendor/github.com/labstack/echo/v4/router.go index 23c5bd3b..86a986a2 100644 --- a/vendor/github.com/labstack/echo/v4/router.go +++ b/vendor/github.com/labstack/echo/v4/router.go @@ -2,6 +2,7 @@ package echo import ( "bytes" + "fmt" "net/http" ) @@ -141,6 +142,51 @@ func NewRouter(e *Echo) *Router { } } +// Routes returns the registered routes. +func (r *Router) Routes() []*Route { + routes := make([]*Route, 0, len(r.routes)) + for _, v := range r.routes { + routes = append(routes, v) + } + return routes +} + +// Reverse generates an URL from route name and provided parameters. +func (r *Router) Reverse(name string, params ...interface{}) string { + uri := new(bytes.Buffer) + ln := len(params) + n := 0 + for _, route := range r.routes { + if route.Name == name { + for i, l := 0, len(route.Path); i < l; i++ { + if (route.Path[i] == ':' || route.Path[i] == '*') && n < ln { + for ; i < l && route.Path[i] != '/'; i++ { + } + uri.WriteString(fmt.Sprintf("%v", params[n])) + n++ + } + if i < l { + uri.WriteByte(route.Path[i]) + } + } + break + } + } + return uri.String() +} + +func (r *Router) add(method, path, name string, h HandlerFunc) *Route { + r.Add(method, path, h) + + route := &Route{ + Method: method, + Path: path, + Name: name, + } + r.routes[method+path] = route + return route +} + // Add registers a new route for method and path with matching handler. func (r *Router) Add(method, path string, h HandlerFunc) { // Validate path |