June 2017
Intermediate to advanced
400 pages
10h 32m
English
Go defines HandlerFuncs and a Handler interface with the following signatures:
// HandlerFunc implements the Handler interfacetype HandlerFunc func(http.ResponseWriter, *http.Request)type Handler interface { ServeHTTP(http.ResponseWriter, *http.Request)}
By default, the net/http package makes extensive use of these types. For example, a route can be attached to a Handler or HandlerFunc interface. This recipe will explore creating a Handler interface, listening on a local port, and performing some operations on an http.ResponseWriter interface after processing http.Request. This should be considered the basis for Go web applications and RESTFul APIs.
Read now
Unlock full access