23 lines
591 B
Go
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)
|
|
}
|
|
}
|