Documentation
¶
Index ¶
- func Broadcast(name string, payload any, opts ...BroadcastOption)
- func Div(name string, value any) string
- func Join(parts ...string) string
- func ListenAndServe(addr, root string) error
- func ListenAndServeTLS(addr, root string) error
- func ListenAndServeTLSWithMux(addr string, mux *http.ServeMux) error
- func ListenAndServeWithMux(addr string, mux *http.ServeMux) error
- func NewMux(root string) *http.ServeMux
- func P(name string, value any) string
- func Raw(html string) string
- func Register(hc *HostComponent)
- func RegisterComponent(c Component)
- func ReleaseSession(session *Session)
- func ResolveRoot(root string) string
- func Span(name string, value any) string
- func Start(root string) error
- func StartAuto() error
- func Tag(tag, name string, value any) string
- type BroadcastOption
- type BroadcastOptions
- type Component
- type Handler
- type HandlerWithSession
- type HostComponent
- func (hc *HostComponent) Handle(payload map[string]any) any
- func (hc *HostComponent) HandleWithSession(session *Session, payload map[string]any) any
- func (hc *HostComponent) Name() string
- func (hc *HostComponent) SessionAware() bool
- func (hc *HostComponent) StoreManager(session *Session) *state.StoreManager
- func (hc *HostComponent) WithInitSnapshot(fn func(*Session, map[string]any) *InitSnapshot) *HostComponent
- type Inbound
- type InitSnapshot
- type Outbound
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Broadcast ¶
func Broadcast(name string, payload any, opts ...BroadcastOption)
Broadcast sends the given payload to all connections subscribed to the component name.
func ListenAndServe ¶
ListenAndServe starts an HTTP server using NewMux to serve files and the WebSocket endpoint.
func ListenAndServeTLS ¶
ListenAndServeTLS starts an HTTPS server using a self-signed certificate and NewMux to serve files and the WebSocket endpoint.
func ListenAndServeTLSWithMux ¶
ListenAndServeTLSWithMux starts an HTTPS server using a self-signed certificate and the provided mux, preserving any additional routes registered by callers.
func ListenAndServeWithMux ¶
ListenAndServeWithMux starts an HTTP server using the provided mux.
func NewMux ¶
NewMux returns an HTTP mux that serves static files from root and the WebSocket handler at /ws.
func Register ¶
func Register(hc *HostComponent)
Register adds a HostComponent to the global registry so incoming messages can be routed to it.
func RegisterComponent ¶
func RegisterComponent(c Component)
RegisterComponent creates a HostComponent from a struct implementing Component and registers it in the global registry. This is the recommended way to define host components — it provides type safety and clean separation.
func ReleaseSession ¶
func ReleaseSession(session *Session)
func ResolveRoot ¶
func Start ¶
Start launches HTTP and HTTPS servers serving files from root. The HTTPS port is the HTTP port + 1.
Types ¶
type BroadcastOption ¶
type BroadcastOption func(*BroadcastOptions)
BroadcastOption configures a broadcast call.
func WithSessionTarget ¶
func WithSessionTarget(sessionID string) BroadcastOption
WithSessionTarget limits a broadcast to a specific session ID.
type BroadcastOptions ¶
type BroadcastOptions struct {
Session string
}
BroadcastOptions holds optional parameters for Broadcast.
type Component ¶
Component is the interface for struct-based host components. Register a struct implementing Component via RegisterComponent.
type Handler ¶
Handler processes inbound payloads for a HostComponent and returns a response payload to send back to the wasm runtime. Returning nil results in no message being sent.
type HandlerWithSession ¶
HandlerWithSession processes inbound payloads with the associated Session.
type HostComponent ¶
type HostComponent struct {
// contains filtered or unexported fields
}
HostComponent represents server-side logic backing an HTML component.
func Get ¶
func Get(name string) (*HostComponent, bool)
Get returns a registered HostComponent by name.
func NewHostComponent ¶
func NewHostComponent(name string, handler Handler) *HostComponent
NewHostComponent registers a handler for the given component name.
func NewHostComponentWithSession ¶
func NewHostComponentWithSession(name string, handler HandlerWithSession) *HostComponent
NewHostComponentWithSession registers a session-aware handler.
func (*HostComponent) Handle ¶
func (hc *HostComponent) Handle(payload map[string]any) any
Handle executes the component's handler.
func (*HostComponent) HandleWithSession ¶
func (hc *HostComponent) HandleWithSession(session *Session, payload map[string]any) any
HandleWithSession executes the session-aware handler when available.
func (*HostComponent) Name ¶
func (hc *HostComponent) Name() string
func (*HostComponent) SessionAware ¶
func (hc *HostComponent) SessionAware() bool
SessionAware reports whether the component registered a session handler.
func (*HostComponent) StoreManager ¶
func (hc *HostComponent) StoreManager(session *Session) *state.StoreManager
StoreManager returns the session-specific store manager when available. If session is nil a reference to the global manager is returned for backward compatibility with legacy handlers.
func (*HostComponent) WithInitSnapshot ¶
func (hc *HostComponent) WithInitSnapshot(fn func(*Session, map[string]any) *InitSnapshot) *HostComponent
WithInitSnapshot registers a callback that produces an InitSnapshot when a resync is requested.
type InitSnapshot ¶
InitSnapshot represents markup the host can send to force the client to repaint a fragment.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents per-connection state for a WebSocket client. It exposes an isolated StoreManager and a context bag for arbitrary data.
func AllocateSession ¶
func AllocateSession() *Session
func SessionByID ¶
SessionByID retrieves a session for the given ID.
func (*Session) ContextDelete ¶
ContextDelete removes a value from the session context.
func (*Session) ContextGet ¶
ContextGet retrieves a value from the session context.
func (*Session) ContextSet ¶
ContextSet stores a value in the session context.
func (*Session) StoreManager ¶
func (s *Session) StoreManager() *state.StoreManager