1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-04-02 14:19:39 -07:00
parent be5148ae27
commit b5d6c05101
22 changed files with 266 additions and 300 deletions

View File

@ -9,15 +9,15 @@ import (
//
// Usage `Echo#Pre(AddTrailingSlash())`
func AddTrailingSlash() echo.MiddlewareFunc {
return func(next echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
url := c.Request().URL()
path := url.Path()
if path != "/" && path[len(path)-1] != '/' {
url.SetPath(path + "/")
}
return next.Handle(c)
})
return next(c)
}
}
}
@ -26,15 +26,15 @@ func AddTrailingSlash() echo.MiddlewareFunc {
//
// Usage `Echo#Pre(RemoveTrailingSlash())`
func RemoveTrailingSlash() echo.MiddlewareFunc {
return func(next echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
url := c.Request().URL()
path := url.Path()
l := len(path) - 1
if path != "/" && path[l] == '/' {
url.SetPath(path[:l])
}
return next.Handle(c)
})
return next(c)
}
}
}