18 lines
289 B
Go
18 lines
289 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.urbach.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()
|
|
}
|