lishwist/http/middleware/prefix.go
2026-02-13 10:36:24 +09:00

23 lines
591 B
Go

package middleware
import (
"net/http"
"strings"
"github.com/Teajey/rsvp"
)
func PrefixMovedPermanently(before, after string) rsvp.HandlerFunc {
return func(w rsvp.ResponseWriter, r *http.Request) rsvp.Body {
suffix := strings.TrimPrefix(r.RequestURI, before)
return rsvp.Blank().StatusMovedPermanently(after + suffix)
}
}
func PrefixPermanentRedirect(before, after string) rsvp.HandlerFunc {
return func(w rsvp.ResponseWriter, r *http.Request) rsvp.Body {
suffix := strings.TrimPrefix(r.RequestURI, before)
return rsvp.Blank().StatusPermanentRedirect(after + suffix)
}
}