mirror of
https://github.com/pikami/cosmium.git
synced 2024-11-25 15:07:35 +00:00
22 lines
454 B
Go
22 lines
454 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/pikami/cosmium/api/config"
|
|
)
|
|
|
|
func StripTrailingSlashes(r *gin.Engine) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
path := c.Request.URL.Path
|
|
if len(path) > 1 && path[len(path)-1] == '/' && !strings.Contains(path, config.Config.ExplorerBaseUrlLocation) {
|
|
c.Request.URL.Path = path[:len(path)-1]
|
|
r.HandleContext(c)
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|