Permalink
Browse files

WriteResponse to wrap the common write logic with error handling

  • Loading branch information...
1 parent 8c049d9 commit db27cde7c3046aae74dfa193b63d2579cbda0092 @daaku committed Jan 2, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 h.go
View
12 h.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"log"
+ "net/http"
)
type HTML interface {
@@ -53,3 +54,14 @@ func Compile(h HTML) HTML {
}
return Unsafe(m)
}
+
+// Writes a HTML response and writes errors on failure.
+func WriteResponse(w http.ResponseWriter, r *http.Request, html HTML) {
+ if r.Method != "HEAD" {
+ _, err := Write(w, html)
+ if err != nil {
+ log.Printf("Error writing HTML for URL: %s: %s", r.URL, err)
+ Write(w, String("FATAL ERROR"))
+ }
+ }
+}

0 comments on commit db27cde

Please sign in to comment.