在请求的 uri 后加上反斜杠
使用
e := echo.New() e.Pre(middleware.AddTrailingSlash())
在请求的 uri 后去除反斜杠
用法
e := echo.New() e.Pre(middleware.RemoveTrailingSlash())
e := echo.New() e.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{ RedirectCode: http.StatusMovedPermanently, }))
这个示例将会加上反斜杠,并且使用 308 - StatusMovedPermanently 重定向。
308 - StatusMovedPermanently
TrailingSlashConfig struct { // Skipper defines a function to skip middleware. Skipper Skipper // Status code to be used when redirecting the request. // Optional, but when provided the request is redirected using this code. RedirectCode int `json:"redirect_code"` }
默认配置
DefaultTrailingSlashConfig = TrailingSlashConfig{ Skipper: defaultSkipper, }
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8