htmgo/templates/starter/main.go

37 lines
736 B
Go
Raw Normal View History

2024-09-23 15:57:59 +00:00
package main
import (
2024-11-01 11:01:18 +00:00
"fmt"
"github.com/maddalax/htmgo/framework/config"
2024-09-23 15:57:59 +00:00
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/service"
"io/fs"
"net/http"
2024-09-23 15:57:59 +00:00
"starter-template/__htmgo"
)
func main() {
locator := service.NewLocator()
2024-11-01 11:01:18 +00:00
cfg := config.Get()
2024-09-23 15:57:59 +00:00
h.Start(h.AppOpts{
ServiceLocator: locator,
LiveReload: true,
Register: func(app *h.App) {
sub, err := fs.Sub(GetStaticAssets(), "assets/dist")
if err != nil {
panic(err)
}
http.FileServerFS(sub)
2024-11-01 11:01:18 +00:00
// change this in htmgo.yml (public_asset_path)
app.Router.Handle(fmt.Sprintf("%s/*", cfg.PublicAssetPath),
http.StripPrefix(cfg.PublicAssetPath, http.FileServerFS(sub)))
__htmgo.Register(app.Router)
2024-09-23 15:57:59 +00:00
},
})
}