Bo-Yi Wu 865e31b3e7
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
Run Tests / lint (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.14 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.15 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.16 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.17 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.18 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.19 (push) Has been cancelled
Run Tests / ubuntu-latest @ Go 1.20 (push) Has been cancelled
Run Tests / macos-latest @ Go (push) Has been cancelled
chore(deps): add go1.20 version
2023-02-08 09:11:10 +08:00
2023-02-08 09:11:10 +08:00
2017-07-03 09:33:06 +08:00
2022-08-30 14:10:01 +08:00
2017-08-25 23:56:46 -05:00
2022-08-30 16:33:00 +08:00
2022-08-30 16:33:00 +08:00
2017-04-16 16:58:27 +08:00
2022-08-30 16:26:03 +08:00

autotls

Run Tests Go Report Card GoDoc Join the chat at https://gitter.im/gin-gonic/autotls

Support Let's Encrypt for a Go server application.

example

example for 1-line LetsEncrypt HTTPS servers.

package main

import (
  "log"
  "net/http"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}

example for custom autocert manager.

package main

import (
  "log"
  "net/http"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
  "golang.org/x/crypto/acme/autocert"
)

func main() {
  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  m := autocert.Manager{
    Prompt:     autocert.AcceptTOS,
    HostPolicy: autocert.HostWhitelist("example1.com", "example2.com"),
    Cache:      autocert.DirCache("/var/www/.cache"),
  }

  log.Fatal(autotls.RunWithManager(r, &m))
}

example usage for graceful shutdown with custom context.

package main

import (
  "context"
  "log"
  "net/http"
  "os/signal"
  "syscall"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
)

func main() {
  // Create context that listens for the interrupt signal from the OS.
  ctx, stop := signal.NotifyContext(
    context.Background(),
    syscall.SIGINT,
    syscall.SIGTERM,
  )
  defer stop()

  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  log.Fatal(autotls.RunWithContext(ctx, r, "example1.com", "example2.com"))
}
Description
autotls
Readme 80 KiB
Languages
Go 100%