htmgo/examples/ws-example/main.go

40 lines
848 B
Go
Raw Normal View History

2024-10-15 18:36:46 +00:00
package main
import (
2024-10-16 20:43:34 +00:00
"github.com/maddalax/htmgo/extensions/websocket"
ws2 "github.com/maddalax/htmgo/extensions/websocket/opts"
2024-10-15 18:36:46 +00:00
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/service"
"io/fs"
"net/http"
2024-10-17 14:53:30 +00:00
"ws-example/__htmgo"
2024-10-15 18:36:46 +00:00
)
func main() {
locator := service.NewLocator()
h.Start(h.AppOpts{
ServiceLocator: locator,
LiveReload: true,
Register: func(app *h.App) {
2024-10-16 20:43:34 +00:00
websocket.EnableExtension(app, ws2.ExtensionOpts{
2024-10-16 20:23:36 +00:00
WsPath: "/ws",
2024-10-16 20:43:34 +00:00
SessionId: func(ctx *h.RequestContext) string {
return ctx.QueryParam("sessionId")
},
2024-10-16 20:23:36 +00:00
})
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)
},
})
}