mirror of
https://github.com/golang/go
synced 2024-11-13 15:00:23 -07:00
http: add Error helper function
R=r, rsc CC=golang-dev https://golang.org/cl/626042
This commit is contained in:
parent
791a26734f
commit
f4322a848d
@ -328,13 +328,16 @@ func (f HandlerFunc) ServeHTTP(c *Conn, req *Request) {
|
|||||||
|
|
||||||
// Helper handlers
|
// Helper handlers
|
||||||
|
|
||||||
// NotFound replies to the request with an HTTP 404 not found error.
|
// Error replies to the request with the specified error message and HTTP code.
|
||||||
func NotFound(c *Conn, req *Request) {
|
func Error(c *Conn, error string, code int) {
|
||||||
c.SetHeader("Content-Type", "text/plain; charset=utf-8")
|
c.SetHeader("Content-Type", "text/plain; charset=utf-8")
|
||||||
c.WriteHeader(StatusNotFound)
|
c.WriteHeader(code)
|
||||||
io.WriteString(c, "404 page not found\n")
|
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
|
// NotFoundHandler returns a simple request handler
|
||||||
// that replies to each request with a ``404 page not found'' reply.
|
// that replies to each request with a ``404 page not found'' reply.
|
||||||
func NotFoundHandler() Handler { return HandlerFunc(NotFound) }
|
func NotFoundHandler() Handler { return HandlerFunc(NotFound) }
|
||||||
|
Loading…
Reference in New Issue
Block a user