18 lines
289 B
Go
18 lines
289 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"git.akyoto.dev/go/web"
|
||
|
)
|
||
|
|
||
|
func RedirectTrailingSlashes(ctx web.Context) error {
|
||
|
path := ctx.Request().Path()
|
||
|
|
||
|
if len(path) > 1 && strings.HasSuffix(path, "/") {
|
||
|
return ctx.Redirect(301, strings.TrimSuffix(path, "/"))
|
||
|
}
|
||
|
|
||
|
return ctx.Next()
|
||
|
}
|