O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required