2015-05-13 23:07:03 -07:00
|
|
|
package middleware
|
|
|
|
|
2015-07-28 15:26:17 -07:00
|
|
|
import "github.com/labstack/echo"
|
2015-05-13 23:07:03 -07:00
|
|
|
|
2015-05-17 22:54:29 -07:00
|
|
|
// StripTrailingSlash returns a middleware which removes trailing slash from request
|
|
|
|
// path.
|
2015-05-13 23:07:03 -07:00
|
|
|
func StripTrailingSlash() echo.HandlerFunc {
|
2015-05-20 14:38:51 -07:00
|
|
|
return func(c *echo.Context) error {
|
2015-05-22 04:40:01 -07:00
|
|
|
p := c.Request().URL.Path
|
2015-05-13 23:07:03 -07:00
|
|
|
l := len(p)
|
|
|
|
if p[l-1] == '/' {
|
2015-05-22 04:40:01 -07:00
|
|
|
c.Request().URL.Path = p[:l-1]
|
2015-05-13 23:07:03 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|