Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gin-gonic/autotls
Support Let's Encrypt for a Go server application.
https://github.com/gin-gonic/autotls
golang letsencrypt tls
Last synced: about 1 month ago
JSON representation
Support Let's Encrypt for a Go server application.
- Host: GitHub
- URL: https://github.com/gin-gonic/autotls
- Owner: gin-gonic
- License: mit
- Created: 2017-04-16T08:58:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T06:15:56.000Z (7 months ago)
- Last Synced: 2024-04-13T20:55:52.689Z (7 months ago)
- Topics: golang, letsencrypt, tls
- Language: Go
- Size: 52.7 KB
- Stars: 360
- Watchers: 14
- Forks: 39
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# autotls
[![Run Tests](https://github.com/gin-gonic/autotls/actions/workflows/go.yml/badge.svg)](https://github.com/gin-gonic/autotls/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/autotls)](https://goreportcard.com/report/github.com/gin-gonic/autotls)
[![GoDoc](https://pkg.go.dev/badge/github.com/gin-gonic/autotls?status.svg)](https://pkg.go.dev/github.com/gin-gonic/autotls)Support Let's Encrypt for a Go server application.
## example
example for 1-line LetsEncrypt HTTPS servers.
```go
package mainimport (
"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.
```go
package mainimport (
"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.
```go
package mainimport (
"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"))
}
```