diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-25 00:46:34 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-25 00:46:34 +0200 |
commit | 40407573e35ff9b617faf84ac715de3d791282e4 (patch) | |
tree | f2f1483b20751a41aaa978761567be798d61cc5d /routes | |
parent | cab4432ec6a3e93286f219a8e6df0c7a57682c5d (diff) | |
download | mdir-40407573e35ff9b617faf84ac715de3d791282e4.tar.gz mdir-40407573e35ff9b617faf84ac715de3d791282e4.tar.bz2 mdir-40407573e35ff9b617faf84ac715de3d791282e4.zip |
ref: Build the whole application in one bin
To make easier to distribute midr all the binaries will embedded into
the final build.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/routes.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/routes/routes.go b/routes/routes.go index 31384a7..873c6c9 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -1,13 +1,17 @@ package routes import ( + "embed" + "html/template" + "net/http" + "git.sr.ht/~gabrielgio/midr/controller" "git.sr.ht/~gabrielgio/midr/db" "git.sr.ht/~gabrielgio/midr/worker" "github.com/gin-gonic/gin" ) -func HandleRequests() { +func HandleRequests(f embed.FS) { models := db.EntryModel{DB: db.DB} worker := worker.NewWorkder() @@ -20,8 +24,11 @@ func HandleRequests() { env.StartScheduler() r := gin.Default() - r.LoadHTMLGlob("templates/*") - r.Static("/assets", "./assets") + + templ := template.Must(template.New("").ParseFS(f, "templates/*.tmpl")) + r.SetHTMLTemplate(templ) + r.StaticFS("/p", http.FS(f)) + r.GET("/", env.GetEntries) r.GET("/entries/", env.GetEntries) r.GET("entries/createEntry", env.GetEntry) |