23 lines
555 B
Go
23 lines
555 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/Teajey/rsvp"
|
|
)
|
|
|
|
func PrefixMovedPermanently(before, after string) rsvp.HandlerFunc {
|
|
return func(h http.Header, r *http.Request) rsvp.Response {
|
|
suffix := strings.TrimPrefix(r.RequestURI, before)
|
|
return rsvp.MovedPermanently(after + suffix)
|
|
}
|
|
}
|
|
|
|
func PrefixPermanentRedirect(before, after string) rsvp.HandlerFunc {
|
|
return func(h http.Header, r *http.Request) rsvp.Response {
|
|
suffix := strings.TrimPrefix(r.RequestURI, before)
|
|
return rsvp.PermanentRedirect(after + suffix)
|
|
}
|
|
}
|