htmgo/examples/todo-list/main.go

44 lines
797 B
Go
Raw Normal View History

2024-09-19 23:13:04 +00:00
package main
import (
2024-09-23 03:46:54 +00:00
"embed"
2024-09-19 23:13:04 +00:00
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/service"
2024-09-19 23:13:04 +00:00
_ "github.com/mattn/go-sqlite3"
2024-09-23 03:46:54 +00:00
"io/fs"
"net/http"
"todolist/__htmgo"
2024-09-19 23:13:04 +00:00
"todolist/ent"
"todolist/infrastructure/db"
)
2024-09-23 03:46:54 +00:00
//go:embed assets/dist/*
var StaticAssets embed.FS
2024-09-19 23:13:04 +00:00
func main() {
locator := service.NewLocator()
service.Set[ent.Client](locator, service.Singleton, func() *ent.Client {
return db.Provide()
})
h.Start(h.AppOpts{
ServiceLocator: locator,
LiveReload: true,
Register: func(app *h.App) {
sub, err := fs.Sub(StaticAssets, "assets/dist")
if err != nil {
panic(err)
}
http.FileServerFS(sub)
app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub)))
__htmgo.Register(app.Router)
2024-09-19 23:13:04 +00:00
},
})
}