oioss
1//https://github.com/gofiber/recipes/blob/master/autocert/main.go
2package utils
3
4import (
5"crypto/tls"
6
7"golang.org/x/crypto/acme/autocert"
8)
9
10func GetTLSConfig(domain string, certdir string) *tls.Config {
11// Certificate manager
12m := &autocert.Manager{
13Prompt: autocert.AcceptTOS,
14// Replace with your domain
15HostPolicy: autocert.HostWhitelist(domain),
16// Folder to store the certificates
17Cache: autocert.DirCache(certdir),
18}
19
20// TLS Config
21cfg := &tls.Config{
22// Get Certificate from Let's Encrypt
23GetCertificate: m.GetCertificate,
24// By default NextProtos contains the "h2"
25// This has to be removed since Fasthttp does not support HTTP/2
26// Or it will cause a flood of PRI method logs
27// http://webconcepts.info/concepts/http-method/PRI
28NextProtos: []string{
29"http/1.1", "acme-tls/1",
30},
31}
32return cfg
33}
34