-
-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathmain.go
36 lines (26 loc) · 832 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"net/http"
"github.com/a-h/templ/examples/integration-gin/gintemplrenderer"
"github.com/gin-gonic/gin"
)
func main() {
engine := gin.Default()
engine.LoadHTMLFiles("./home.html")
//engine.HTMLRender = gintemplrenderer.Default
ginHtmlRenderer := engine.HTMLRender
engine.HTMLRender = &gintemplrenderer.HTMLTemplRenderer{FallbackHtmlRenderer: ginHtmlRenderer}
// Disable trusted proxy warning.
engine.SetTrustedProxies(nil)
engine.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "", Home())
})
engine.GET("/with-ctx", func(c *gin.Context) {
r := gintemplrenderer.New(c.Request.Context(), http.StatusOK, Home())
c.Render(http.StatusOK, r)
})
engine.GET("/with-fallback-renderer", func(c *gin.Context) {
c.HTML(http.StatusOK, "home.html", gin.H{})
})
engine.Run(":8080")
}