Refactored redir middleware to return errors

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

View File

@ -41,15 +41,15 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
redirects = append(redirects, rule) redirects = append(redirects, rule)
} }
return func(next http.HandlerFunc) http.HandlerFunc { return func(next middleware.HandlerFunc) middleware.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) (int, error) {
for _, rule := range redirects { for _, rule := range redirects {
if r.URL.Path == rule.From { if r.URL.Path == rule.From {
http.Redirect(w, r, rule.To, rule.Code) http.Redirect(w, r, rule.To, rule.Code)
break break
} }
} }
next(w, r) return next(w, r)
} }
}, nil }, nil
} }