Support Let’s Encrypt

example for 1-line LetsEncrypt HTTPS servers.

  1. package main
  2. import (
  3. "log"
  4. "github.com/gin-gonic/autotls"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func main() {
  8. r := gin.Default()
  9. // Ping handler
  10. r.GET("/ping", func(c *gin.Context) {
  11. c.String(200, "pong")
  12. })
  13. log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
  14. }

example for custom autocert manager.

  1. package main
  2. import (
  3. "log"
  4. "github.com/gin-gonic/autotls"
  5. "github.com/gin-gonic/gin"
  6. "golang.org/x/crypto/acme/autocert"
  7. )
  8. func main() {
  9. r := gin.Default()
  10. // Ping handler
  11. r.GET("/ping", func(c *gin.Context) {
  12. c.String(200, "pong")
  13. })
  14. m := autocert.Manager{
  15. Prompt: autocert.AcceptTOS,
  16. HostPolicy: autocert.HostWhitelist("example1.com", "example2.com"),
  17. Cache: autocert.DirCache("/var/www/.cache"),
  18. }
  19. log.Fatal(autotls.RunWithManager(r, &m))
  20. }

Last modified March 7, 2020 : add blog dir (#115) (f46734b)