18 lines
289 B
Go
Raw Normal View History

2025-01-21 14:00:40 +01:00
package middleware
import (
"strings"
2025-02-25 17:01:59 +01:00
"git.urbach.dev/go/web"
2025-01-21 14:00:40 +01:00
)
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()
}