sse

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 4 Imported by: 2

README

tinysse

Client and Event Server, SSE (Server-Sent Events) protocol compatible with Go (Server) and TinyGo (WASM Client).

Get Started

Installation

go get github.com/tinywasm/sse

Quick Links

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c *Config) *tinySSE

New creates a new tinySSE instance with shared configuration.

Types

type ClientConfig

type ClientConfig struct {
	// Endpoint is the SSE server URL.
	Endpoint string

	// RetryInterval in milliseconds for reconnection.
	RetryInterval int

	// MaxRetryDelay caps the exponential backoff.
	MaxRetryDelay int

	// MaxReconnectAttempts limits retry attempts. 0 = unlimited.
	MaxReconnectAttempts int
}

ClientConfig holds configuration strictly for the Browser/WASM Client.

type Config

type Config struct {
	// Log is the centralized logger function.
	// If nil, logging is disabled.
	Log func(args ...any)
}

Config holds the shared configuration for both Server and Client.

type SSEClient

type SSEClient struct {
	// contains filtered or unexported fields
}

SSEClient is the SSE client for WASM.

func (*SSEClient) Close

func (c *SSEClient) Close()

Close closes the SSE connection.

func (*SSEClient) Connect

func (c *SSEClient) Connect()

Connect establishes a connection to the SSE endpoint.

func (*SSEClient) OnError

func (c *SSEClient) OnError(handler func(err error))

OnError sets the handler for errors.

func (*SSEClient) OnMessage

func (c *SSEClient) OnMessage(handler func(msg *SSEMessage))

OnMessage sets the handler for incoming messages.

type SSEMessage

type SSEMessage struct {
	ID    string // SSE "id:" field - Required. Used for Last-Event-ID reconnection.
	Event string // SSE "event:" field - Optional. Allows routing to different handlers.
	Data  []byte // SSE "data:" field - RAW bytes, library does NOT parse.
}

SSEMessage represents a message sent over SSE. Shared by both Server (for broadcasting) and Client (for consumption).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL