1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:54:39 -07:00

http: add Error helper function

R=r, rsc
CC=golang-dev
https://golang.org/cl/626042
This commit is contained in:
Andrew Gerrand 2010-03-20 10:22:09 +11:00
parent 791a26734f
commit f4322a848d

View File

@ -328,13 +328,16 @@ func (f HandlerFunc) ServeHTTP(c *Conn, req *Request) {
// Helper handlers
// NotFound replies to the request with an HTTP 404 not found error.
func NotFound(c *Conn, req *Request) {
// Error replies to the request with the specified error message and HTTP code.
func Error(c *Conn, error string, code int) {
c.SetHeader("Content-Type", "text/plain; charset=utf-8")
c.WriteHeader(StatusNotFound)
io.WriteString(c, "404 page not found\n")
c.WriteHeader(code)
fmt.Fprintln(c, error)
}
// NotFound replies to the request with an HTTP 404 not found error.
func NotFound(c *Conn, req *Request) { Error(c, "404 page not found", StatusNotFound) }
// NotFoundHandler returns a simple request handler
// that replies to each request with a ``404 page not found'' reply.
func NotFoundHandler() Handler { return HandlerFunc(NotFound) }