How to do it...

  1. Create https-server.go, where we will define a handler that will just write Hello World! to an HTTP response stream for all HTTPS requests, as follows:
package mainimport (  "fmt"  "log"  "net/http")const (  CONN_HOST = "localhost"  CONN_PORT = "8443"  HTTPS_CERTIFICATE = "domain.crt"  DOMAIN_PRIVATE_KEY = "domain.key")func helloWorld(w http.ResponseWriter, r *http.Request) {  fmt.Fprintf(w, "Hello World!")}func main() {  http.HandleFunc("/", helloWorld)  err := http.ListenAndServeTLS(CONN_HOST+":"+CONN_PORT,  HTTPS_CERTIFICATE, DOMAIN_PRIVATE_KEY, nil)  if err != nil   {    log.Fatal("error starting https server : ", err)    return  }}
  1. Run the program with the following command:
$ go run https-server.go

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.