gin/examples/http2/main.go

39 lines
729 B
Go
Raw Normal View History

2017-07-11 04:03:09 +03:00
package main
import (
"html/template"
"log"
"net/http"
"os"
2017-07-11 04:03:09 +03:00
"github.com/gin-gonic/gin"
)
var html = template.Must(template.New("https").Parse(`
<html>
<head>
<title>Https Test</title>
</head>
<body>
<h1 style="color:red;">Welcome, Ginner!</h1>
</body>
</html>
`))
func main() {
logger := log.New(os.Stderr, "", 0)
logger.Println("[WARNING] DON'T USE THE EMBED CERTS FROM THIS EXAMPLE IN PRODUCTION ENVIRONMENT, GENERATE YOUR OWN!")
2017-07-11 04:03:09 +03:00
r := gin.Default()
r.SetHTMLTemplate(html)
r.GET("/welcome", func(c *gin.Context) {
c.HTML(http.StatusOK, "https", gin.H{
2017-07-11 04:03:09 +03:00
"status": "success",
})
})
// Listen and Server in https://127.0.0.1:8080
r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")
}