New Render API

This commit is contained in:
Manu Mtz-Almeida
2015-05-18 15:45:24 +02:00
parent 3066c35754
commit 947b53d4a2
13 changed files with 190 additions and 229 deletions
+10 -12
View File
@@ -5,18 +5,16 @@ import (
"net/http"
)
type redirectRender struct{}
type Redirect struct {
Code int
Request *http.Request
Location string
}
func (_ redirectRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
req := data[0].(*http.Request)
location := data[1].(string)
WriteRedirect(w, code, req, location)
func (r Redirect) Write(w http.ResponseWriter) error {
if r.Code < 300 || r.Code > 308 {
panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
}
http.Redirect(w, r.Request, r.Location, r.Code)
return nil
}
func WriteRedirect(w http.ResponseWriter, code int, req *http.Request, location string) {
if code < 300 || code > 308 {
panic(fmt.Sprintf("Cannot redirect with status code %d", code))
}
http.Redirect(w, req, location, code)
}