How do I set the HTTP status code on an http.ResponseWriter
(e.g. to 500 or 403)?
I can see that requests normally have a status code of 200 attached to the
Apart from WriteHeader(int)
you can use the helper method http.Error, for example:
func yourFuncHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "my own error message", http.StatusForbidden)
// or using the default message error
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}
http.Error() and http.StatusText() methods are your friends