github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/http/fast/cert/autocert.go (about)

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