You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can build a server into a single binary containing templates by using the [embed](https://pkg.go.dev/embed) package.
// loadTemplate loads templates embedded by go-assets-builder
1908
-
funcloadTemplate() (*template.Template, error) {
1909
-
t:= template.New("")
1910
-
forname, file:=range Assets.Files {
1911
-
defer file.Close()
1912
-
if file.IsDir() || !strings.HasSuffix(name, ".tmpl") {
1913
-
continue
1914
-
}
1915
-
h, err:= ioutil.ReadAll(file)
1916
-
if err != nil {
1917
-
returnnil, err
1918
-
}
1919
-
t, err = t.New(name).Parse(string(h))
1920
-
if err != nil {
1921
-
returnnil, err
1922
-
}
1923
-
}
1924
-
return t, nil
1917
+
router.GET("/foo", func(c *gin.Context) {
1918
+
c.HTML(http.StatusOK, "bar.tmpl", gin.H{
1919
+
"title": "Foo website",
1920
+
})
1921
+
})
1922
+
1923
+
router.GET("favicon.ico", func(c *gin.Context) {
1924
+
file, _:= f.ReadFile("assets/favicon.ico")
1925
+
c.Data(
1926
+
http.StatusOK,
1927
+
"image/x-icon",
1928
+
file,
1929
+
)
1930
+
})
1931
+
1932
+
router.Run(":8080")
1925
1933
}
1926
1934
```
1927
1935
1928
-
See a complete example in the `https://github.com/gin-gonic/examples/tree/master/assets-in-binary` directory.
1936
+
See a complete example in the `https://github.com/gin-gonic/examples/tree/master/assets-in-binary/example02` directory.
0 commit comments