Closed
Description
Maybe it's possible to integrate the following to get automatically ssl certificates from Let's Encrypt.
Resources:
https://godoc.org/golang.org/x/crypto
https://godoc.org/golang.org/x/crypto/acme/autocert
Sample Integration Diff (Not tested):
diff --git a/libcentrifugo/server/httpserver/handlers.go b/libcentrifugo/server/httpserver/handlers.go
index 9105bb2..3753370 100644
--- a/libcentrifugo/server/httpserver/handlers.go
+++ b/libcentrifugo/server/httpserver/handlers.go
@@ -21,6 +21,8 @@ import (
"github.com/gorilla/websocket"
"github.com/igm/sockjs-go/sockjs"
"github.com/rakyll/statik/fs"
+
+ "golang.org/x/crypto/acme/autocert"
)
// HandlerFlag is a bit mask of handlers that must be enabled in mux.
@@ -82,7 +84,19 @@ var DefaultMuxOptions = MuxOptions{
func listenHTTP(mux http.Handler, addr string, useSSL bool, sslCert, sslKey string, wg *sync.WaitGroup) {
defer wg.Done()
if useSSL {
- if err := http.ListenAndServeTLS(addr, sslCert, sslKey, mux); err != nil {
+ certManager := autocert.Manager{
+ Prompt: autocert.AcceptTOS,
+ HostPolicy: autocert.HostWhitelist("ws.sample.com"), //your domain here
+ Cache: autocert.DirCache("certs"), //folder for storing certificates
+ }
+ server := &http.Server{
+ Addr: addr,
+ Handler: mux,
+ TLSConfig: &tls.Config{
+ GetCertificate: certManager.GetCertificate,
+ },
+ }
+ if err := server.ListenAndServeTLS("", ""); err != nil { //key and cert are comming from Let's Encrypt
logger.FATAL.Fatalln("ListenAndServe:", err)
}
} else {
I'm using this already in a other go server and it's working.
Metadata
Assignees
Labels
No labels