sse

package module
v0.0.0-...-dba2c48 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 9 Imported by: 0

README

Server-Sent Events

License

Installation

go get github.com/gowool/middleware/sse

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	ClientKey      = "sse_client"
	EventConnected = "connected"
	EventClosing   = "closing"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID        string
	Idle      time.Duration
	EventChan chan render.SSEvent
	Done      chan struct{}
}

type Config

type Config struct {
	ClientIdle time.Duration  `mapstructure:"client_idle"`
	Metrics    *MetricsConfig `mapstructure:"metrics"`
}

func (*Config) Init

func (cfg *Config) Init()

type Event

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

func New

func New(cfg *Config, log *slog.Logger) *Event

func (*Event) Broadcast

func (e *Event) Broadcast(event render.SSEvent)

func (*Event) Close

func (e *Event) Close() error

func (*Event) Handler

func (e *Event) Handler(c wool.Ctx) error

func (*Event) Middleware

func (e *Event) Middleware(next wool.Handler) wool.Handler

func (*Event) Notify

func (e *Event) Notify(clientID string, event render.SSEvent)

func (*Event) Subscribe

func (e *Event) Subscribe(cl Client)

func (*Event) Unsubscribe

func (e *Event) Unsubscribe(clientID string)

type MetricsConfig

type MetricsConfig struct {
	Enabled   bool   `mapstructure:"enabled"`
	Version   string `mapstructure:"version"`
	Namespace string `mapstructure:"namespace"`
}

Jump to

Keyboard shortcuts

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