htmgo/examples/sse-with-state/main.go

36 lines
705 B
Go
Raw Normal View History

2024-10-15 18:36:46 +00:00
package main
import (
2024-10-16 20:23:36 +00:00
websocket "github.com/maddalax/htmgo/extensions/ws"
2024-10-15 18:36:46 +00:00
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/service"
"io/fs"
"net/http"
"sse-with-state/__htmgo"
)
func main() {
locator := service.NewLocator()
h.Start(h.AppOpts{
ServiceLocator: locator,
LiveReload: true,
Register: func(app *h.App) {
2024-10-16 20:23:36 +00:00
websocket.EnableExtension(app, websocket.WsExtensionOpts{
WsPath: "/ws",
})
2024-10-15 18:36:46 +00:00
sub, err := fs.Sub(GetStaticAssets(), "assets/dist")
if err != nil {
panic(err)
}
http.FileServerFS(sub)
app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub)))
__htmgo.Register(app.Router)
},
})
}