From e82ed049705211dd46944d7fe01d2cf71585e446 Mon Sep 17 00:00:00 2001 From: maddalax Date: Sun, 22 Sep 2024 22:46:54 -0500 Subject: [PATCH] embed assets --- examples/todo-list/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/todo-list/main.go b/examples/todo-list/main.go index f37ebe2..b01f0ca 100644 --- a/examples/todo-list/main.go +++ b/examples/todo-list/main.go @@ -1,15 +1,20 @@ package main import ( + "embed" "github.com/labstack/echo/v4" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" _ "github.com/mattn/go-sqlite3" + "io/fs" "todolist/__htmgo" "todolist/ent" "todolist/infrastructure/db" ) +//go:embed assets/dist/* +var StaticAssets embed.FS + func main() { locator := service.NewLocator() @@ -17,10 +22,18 @@ func main() { return db.Provide() }) + sub, err := fs.Sub(StaticAssets, "assets/dist") + + if err != nil { + panic(err) + } + h.Start(h.AppOpts{ ServiceLocator: locator, LiveReload: true, Register: func(e *echo.Echo) { + e.StaticFS("/public", sub) + e.Static("/public", "./assets/dist") __htmgo.Register(e) },