From f1539d34942bcb9e70d7758882308578320f8f0c Mon Sep 17 00:00:00 2001 From: Richard Collins Date: Thu, 13 Nov 2014 16:03:47 +1300 Subject: [PATCH 1/2] Change Error and Status to print textual status codes --- render.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/render.go b/render.go index 807e801..9c00c4f 100644 --- a/render.go +++ b/render.go @@ -41,7 +41,7 @@ import ( "encoding/xml" "fmt" "html/template" - "io" + "io" "io/ioutil" "net/http" "os" @@ -92,6 +92,8 @@ type Render interface { Error(status int) // Status is an alias for Error (writes an http status to the http.ResponseWriter) Status(status int) + // StatusText is the same as Status except it allows you to customise the error text. + StatusText(status int, text string) // Redirect is a convienience function that sends an HTTP redirect. If status is omitted, uses 302 (Found) Redirect(location string, status ...int) // Template returns the internal *template.Template used to render the HTML @@ -325,10 +327,15 @@ func (r *renderer) Data(status int, v []byte) { // Error writes the given HTTP status to the current ResponseWriter func (r *renderer) Error(status int) { - r.WriteHeader(status) + r.Status(status) } func (r *renderer) Status(status int) { + r.StatusText(status, http.StatusText(status)) +} + +func (r *renderer) StatusText(status int, text string) { + fmt.Fprint(r, status, " ", text) r.WriteHeader(status) } From bdaac41b4ea8a1f874d36e3afb28a86e214983c8 Mon Sep 17 00:00:00 2001 From: Richard Collins Date: Thu, 4 Dec 2014 09:03:11 +1300 Subject: [PATCH 2/2] Fix bug Status always sending 200 status code --- render.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render.go b/render.go index 9c00c4f..487c44b 100644 --- a/render.go +++ b/render.go @@ -335,8 +335,8 @@ func (r *renderer) Status(status int) { } func (r *renderer) StatusText(status int, text string) { - fmt.Fprint(r, status, " ", text) r.WriteHeader(status) + fmt.Fprint(r, status, " ", text) } func (r *renderer) Redirect(location string, status ...int) {