How to Use HTTPS/TLS with a Go HTTP Server

Web
Start a Go HTTPS server by calling http.ListenAndServeTLS with your certificate and key file paths.

Use http.ListenAndServeTLS with your certificate and key files to start a secure server. This function handles TLS handshake and serves HTTP requests over HTTPS.

package main

import (
	"log"
	"net/http"
)

func main() {
	log.Fatal(http.ListenAndServeTLS(":443", "cert.pem", "key.pem", nil))
}