Use embedded files

This commit is contained in:
Jan Bader 2021-11-07 22:01:13 +00:00
parent f33d4b6cae
commit 4b08de00b8

View File

@ -4,7 +4,10 @@ import (
"net/http" "net/http"
"time" "time"
"html/template"
"git.javil.eu/jacob1123/budgeteer" "git.javil.eu/jacob1123/budgeteer"
"git.javil.eu/jacob1123/budgeteer/web"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -25,8 +28,10 @@ const (
func (h *Handler) Serve() { func (h *Handler) Serve() {
router := gin.Default() router := gin.Default()
router.LoadHTMLGlob("./templates/*") templ := template.Must(template.New("").Funcs(router.FuncMap).ParseFS(web.Templates, "*"))
router.Static("/static", "./static") router.SetHTMLTemplate(templ)
router.StaticFS("/static", http.FS(web.Static))
router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index", nil) }) router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index", nil) })
router.GET("/login", h.login) router.GET("/login", h.login)