Golang: HTTP & Networking
Secure HTTPS servers in Go
In this article, we are going to look at some of the basic APIs of the http
package to create and initialize HTTPS servers in Go.
In the “Simple Hello World Server” lesson, we learned about net/http
package, how to create routes and how ServeMux
works. In the “Running multiple HTTP servers” lesson, we learned about Server
structure and how to run multiple HTTP servers concurrently.
In this lesson, we are going to create an HTTPS server using both Go’s standard server configuration and custom configuration (using Server
structure). But before this, we need to know what HTTPS really is?
HTTPS is a big topic of discussion in itself. Hence while writing this lesson, I published an article just on “How HTTPS works?”. I advise you to read this lesson first before continuing this article. In this article, I’ve also described the encryption paradigm and SSL certificates generation process.
If we recall the simplest HTTP server example from previous lessons, we only need http.ListenAndServe
function to start an HTTP server and http.HandleFunc
to register a response handler for a particular endpoint.