mirror of
https://github.com/pikami/cosmium.git
synced 2024-12-01 18:07:44 +00:00
18 lines
350 B
Go
18 lines
350 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func TrailingSlashStripper() gin.HandlerFunc {
|
||
|
return func(c *gin.Context) {
|
||
|
if (len(c.Request.URL.Path)) > 1 { //dont strip root dir slash, path="/"
|
||
|
var stripped_path = strings.TrimSuffix(c.Request.URL.Path, "/")
|
||
|
c.Request.URL.Path = stripped_path
|
||
|
}
|
||
|
c.Next()
|
||
|
}
|
||
|
}
|