From 6f20b843362404e2676ad2b0f2f9462222ca8f33 Mon Sep 17 00:00:00 2001 From: itsmrval Date: Fri, 2 Aug 2024 14:09:41 +0200 Subject: [PATCH] fix(templates) correcting template directory --- index.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.go b/index.go index 6c14db9..5109832 100644 --- a/index.go +++ b/index.go @@ -2,8 +2,10 @@ package main import ( "database/sql" + "embed" "encoding/json" "fmt" + "html/template" "io/ioutil" "log" "net/http" @@ -17,6 +19,8 @@ import ( "golang.org/x/oauth2/github" ) +var templatesFS embed.FS + type Link struct { ID string OriginalURL string @@ -43,6 +47,8 @@ func initialize() (*App, error) { oauthConfig := initGithubOAuth() router := gin.Default() + tmpl := template.Must(template.ParseFS(templatesFS, "templates/*")) + router.SetHTMLTemplate(tmpl) return &App{ DB: db, @@ -80,7 +86,6 @@ func initGithubOAuth() *oauth2.Config { } func (app *App) SetupRoutes() { - app.Router.LoadHTMLGlob("templates/*") app.Router.Static("/static", "./static") app.Router.GET("/", app.homePage) app.Router.POST("/", app.shortenURL)