Refactored rewrite middleware to return errors

This commit is contained in:
Matthew Holt 2015-03-28 16:49:18 -06:00
parent c657948824
commit 878ae7ea89

View file

@ -28,15 +28,16 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
rewrites = append(rewrites, rule)
}
return func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO: Why can't we just return an http.Handler here instead?
return func(next middleware.HandlerFunc) middleware.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) (int, error) {
for _, rule := range rewrites {
if r.URL.Path == rule.From {
r.URL.Path = rule.To
break
}
}
next(w, r)
return next(w, r)
}
}, nil
}