package main import ( "log" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, HTTPS World!")) }) err := http.ListenAndServeTLS(":443", "cert.pem", "key.pem", nil) if err != nil { log.Fatal(err) } }
package main import ( "crypto/tls" "log" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, HTTPS World!")) }) config := &tls.Config{ MinVersion: tls.VersionTLS12, CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, PreferServerCipherSuites: true, CipherSuites: []uint16{ tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, }, } server := &http.Server{ Addr: ":443", TLSConfig: config, } err := server.ListenAndServeTLS("cert.pem", "key.pem") if err != nil { log.Fatal(err) } }Both examples demonstrate how to create an HTTPS server that listens on port 443 using the ListenAndServeTLS function. Example 1 uses the default TLS configuration, while Example 2 creates a custom TLS configuration with specific cipher suites and curve preferences.