慕后森
这是一种简单的方法,让letsencrypt为您处理证书:)func main() { r := mux.NewRouter() r.HandleFunc("/index", index) certManager := autocert.Manager{ Prompt: autocert.AcceptTOS, HostPolicy: autocert.HostWhitelist("www.example.com"), // replace with your domain Cache: autocert.DirCache("certs"), } srv := &http.Server{ Handler: r, Addr: ":https", WriteTimeout: 5 * time.Second, ReadTimeout: 5 * time.Second, TLSConfig: &tls.Config{ GetCertificate: certManager.GetCertificate, }, } go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) //nolint log.Fatal(srv.ListenAndServeTLS("", ""))}