Read this in other languages: English, 中文.
easytls-sdk-go is a certificate generation service based on lego's tls, which can stably replace certificates for online services without requiring a restart with just simple configuration.
go get github.com/Green-rainBit/easytls-sdk-go@latestObtain Certificate Directly from Let's EncryptFill in the email and key in the easytls.TlsClientConfig, then fill in the configuration information corresponding to the certificate's domain name.You need to pre-obtain the email and key from Let's Encrypt.
package main
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"github.com/Green-rainBit/easytls-sdk-go/easytls"
"github.com/Green-rainBit/easytls-sdk-go/esaylego"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
fmt.Fprint(res, "Running HTTPS Server!!\n")
})
legoConfigUser := esaylego.NewLegoConfigUser("",
"",
)
easytlsConfig := easytls.TlsClientConfig{
Domains: []string{"domain.cn"},
LegoConfigUser: legoConfigUser,
LegoConfig: esaylego.NewLegoConfigByUser(legoConfigUser),
DnsConfig: map[string]string{
"DNS_CHALLENGE": "alidns",
"ALICLOUD_ACCESS_KEY": "",
"ALICLOUD_SECRET_KEY": "",
},
}
easytlsClient, err := easytls.NewLegoClient(easytlsConfig)
if err != nil {
log.Fatal(err)
}
srv := &http.Server{
Addr: fmt.Sprintf(":%d", 8443),
Handler: mux,
TLSConfig: &tls.Config{
GetCertificate: easytlsClient.GetCertificate(),
},
}
srv.ListenAndServeTLS("", "")
}Just modify the TlsClientConfig configuration content
easytlsConfig := easytls.TlsClientConfig{
CertFile: "cert.pem",
KeyFile: "key.pem",
}Use in conjunction with easy-tls-server
easytlsConfig := easytls.TlsClientConfig{
Domains: []string{"www.furniturestore.cn"},
Host: "127.0.0.1:8888",
Scheme: "http",
}
Detailed documentation is available here.