How it works...
The net/http package contains a few ways of creating the HTTP server. The most simple one is to implement the Handler interface from the net/http package. The Handler interface requires the type to implement the ServeHTTP method. This method handles the request and response.
The server itself is created in the form of the Server struct from the net/http package. The Server struct requires the Handler and Addr fields. By calling the method, ListenAndServe, the server starts serving the content on the given address.
If the Serve method of the Server is used, then the Listener must be provided.
The net/http package provides also the default server which could be used if the ListenAndServe is called as a function from the net/http ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access