gin/examples/auto-tls/main.go

21 lines
345 B
Go
Raw Normal View History

2017-04-03 16:23:45 +03:00
package main
import (
"github.com/gin-gonic/gin"
2017-04-03 18:30:46 +03:00
"golang.org/x/crypto/acme/autocert"
2017-04-03 16:23:45 +03:00
)
func main() {
r := gin.Default()
2017-04-03 18:30:46 +03:00
gin.AutoTLSManager.Cache = autocert.DirCache("/var/www/.cache")
2017-04-03 16:23:45 +03:00
// Ping handler
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
// Listen and Server in 0.0.0.0:443
2017-04-03 18:30:46 +03:00
r.RunAutoTLS("example.com")
2017-04-03 16:23:45 +03:00
}