Skip to content

Instantly share code, notes, and snippets.

@AlekSi
Created August 5, 2014 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlekSi/7885d53bc23e12ad0c79 to your computer and use it in GitHub Desktop.
Save AlekSi/7885d53bc23e12ad0c79 to your computer and use it in GitHub Desktop.
func check(err error) {
if err != nil {
panic(err)
}
}
func (h *APIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
defer func() {
if p := recover(); p != nil {
switch e := p.(type) {
case *silentError:
// nothing
case *clientError:
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
rw.WriteHeader(400)
fmt.Fprintln(rw, e.err.Error())
default:
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
rw.WriteHeader(500)
fmt.Fprintln(rw, "internal error")
}
}
}
...
}
func (h *APIHandler) Updates(rw http.ResponseWriter, req *http.Request) {
...
check(err)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment