main.go 729 B

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