How it works...

Once we run the program, the HTTPS server will start locally listening on port 8443.

Browsing https://localhost:8443/ will give us Hello World! as a response from the server:

Moreover, executing a GET request from the command line passing the --insecure flag with curl will skip the certificate validation, as we are using a self-signed certificate:

$ curl -X GET https://localhost:8443/ --insecure Hello World!

Let's understand the program we have written:

  • const (CONN_HOST = "localhost" CONN_PORT = "8443" HTTPS_CERTIFICATE = "domain.crt" DOMAIN_PRIVATE_KEY = "domain.key"): Here, we declared four constants - CONN_HOST with the ...

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.