Skip to content

Commit

Permalink
WriteResponse to wrap the common write logic with error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
daaku committed Jan 2, 2013
1 parent 8c049d9 commit db27cde
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions h.go
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"log"
"net/http"
)

type HTML interface {
Expand Down Expand Up @@ -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.