Skip to content

Instantly share code, notes, and snippets.

@smallnest
Created August 24, 2018 03:56
Show Gist options
  • Select an option

  • Save smallnest/d3cdaa3cbcd0f2880375e16dbd26cb96 to your computer and use it in GitHub Desktop.

Select an option

Save smallnest/d3cdaa3cbcd0f2880375e16dbd26cb96 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/tls"
"fmt"
"net/http"
"golang.org/x/crypto/acme/autocert"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello Secure World")
})
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
Cache: autocert.DirCache("certs"),
}
server := &http.Server{
Addr: ":443",
Handler: mux,
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
go http.ListenAndServe(":80", certManager.HTTPHandler(nil))
server.ListenAndServeTLS("", "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment