October 2015
Beginner to intermediate
400 pages
14h 44m
English
http.Handler Interface
In Chapter 1, we saw a glimpse of how to use
the net/http package to implement web clients
(§1.5) and servers (§1.7).
In this section, we’ll look more closely at the server API, whose
foundation is the http.Handler interface:
package http
type Handler interface {
ServeHTTP(w ResponseWriter, r *Request)
}
func ListenAndServe(address string, h Handler) error
The ListenAndServe function requires a server address, such
as "localhost:8000", and an instance
of the Handler interface to which all requests should be
dispatched.
It runs forever, or until the server fails (or fails to start) with an
error, always non-nil, which it returns.
Imagine an e-commerce site with a database ...