main.go 707 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "html/template"
  4. "log"
  5. "os"
  6. "github.com/gin-gonic/gin"
  7. )
  8. var html = template.Must(template.New("https").Parse(`
  9. <html>
  10. <head>
  11. <title>Https Test</title>
  12. </head>
  13. <body>
  14. <h1 style="color:red;">Welcome, Ginner!</h1>
  15. </body>
  16. </html>
  17. `))
  18. func main() {
  19. logger := log.New(os.Stderr, "", 0)
  20. logger.Println("[WARNING] DON'T USE THE EMBED CERTS FROM THIS EXAMPLE IN PRODUCTION ENVIRONMENT, GENERATE YOUR OWN!")
  21. r := gin.Default()
  22. r.SetHTMLTemplate(html)
  23. r.GET("/welcome", func(c *gin.Context) {
  24. c.HTML(200, "https", gin.H{
  25. "status": "success",
  26. })
  27. })
  28. // Listen and Server in https://127.0.0.1:8080
  29. r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")
  30. }