gin
gin copied to clipboard
router.Static can not run in https mode
router.Static can not run in https mode ,errors: http: TLS handshake error from [::1]:14521: remote error: tls: unknown certificate
package main
import (
"github.com/gin-gonic/gin"
"github.com/unrolled/secure"
)
func main() {
router := gin.Default()
router.Use(TlsHandler())
router.Static("/html", "/html") //Static file handler
// Ping handler
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
router.RunTLS(":8080", "cert.pem", "key.pem")
}
func TlsHandler() gin.HandlerFunc {
return func(c *gin.Context) {
secureMiddleware := secure.New(secure.Options{
SSLRedirect: true,
SSLHost: "localhost:8080",
})
err := secureMiddleware.Process(c.Writer, c.Request)
// If there was an error, do not continue.
if err != nil {
return
}
c.Next()
}
}
it means your certficate is not signed, what kind of certificae are you using?