Read this in other languages: English, 中文.
easytls-sdk-go
Introduce
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.
User Instructions
Obtain Certificate Directly from Let's EncryptFill in the email and key in the tls-api.yaml file, 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.
go get github.com/Green-rainBit/easytls-sdk-go@last
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("", "")
}
Support for Manual Hot Swapping
Just modify the TlsClientConfig configuration content
easytlsConfig := easytls.TlsClientConfig{
CertFile: "cert.pem",
KeyFile: "key.pem",
}
easytlsConfig := easytls.TlsClientConfig{
Domains: []string{"www.furniturestore.cn"},
Host: "127.0.0.1:8888",
Scheme: "http",
}
Supported DNS operators
Detailed documentation is available here.
你可以将上述内容保存为 `README.md` 文件,以提供英文版的文档说明。