mirror of
https://github.com/labstack/echo.git
synced 2024-12-14 10:23:00 +02:00
b6547dde66
Signed-off-by: Vishal Rana <vr@labstack.com>
1.2 KiB
1.2 KiB
+++ title = "TrailingSlash Middleware" description = "Trailing slash middleware for Echo" [menu.side] name = "TrailingSlash" parent = "middleware" weight = 5 +++
AddTrailingSlash Middleware
AddTrailingSlash middleware adds a trailing slash to the request URI.
Usage
e := echo.New()
e.Pre(middleware.AddTrailingSlash())
RemoveTrailingSlash Middleware
RemoveTrailingSlash middleware removes a trailing slash from the request URI.
Usage
e := echo.New()
e.Pre(middleware.RemoveTrailingSlash())
Custom Configuration
Usage
e := echo.New()
e.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{
RedirectCode: http.StatusMovedPermanently,
}))
Example above will add a trailing slash to the request URI and redirect with 308 - StatusMovedPermanently
.
Configuration
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"`
}
Default Configuration
DefaultTrailingSlashConfig = TrailingSlashConfig{
Skipper: defaultSkipper,
}