sse

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidUserID              = errors.New("invalid user id")
	ErrNotFoundConnectedUser      = errors.New("not found connected user")
	ErrResponseWriterIsNotFlusher = errors.New("response does not support flush")
)

All kind of errors

View Source
var (
	ContextUserID utils.ContextKey = "userID"
)

Describe all context keys

Functions

func FormatMSG

func FormatMSG(event string, data ...string) []byte

FormatMSG prepare bytes to send

func Run

func Run(ch chan Message, w http.ResponseWriter, r *http.Request) error

Run listener of channel and prepare messages

Types

type Message

type Message struct {
	Event string
	Text  []string
}

Message message

func NewMessage

func NewMessage(event string, data ...string) Message

NewMessage return new message

type Pool

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

Pool contains all connections and could delivery messages

func NewPool

func NewPool(bufferSize int) *Pool

NewPool return new handler

func (*Pool) Add

func (h *Pool) Add(userID string) chan Message

Add add new connection

func (*Pool) Connections

func (h *Pool) Connections() int

Connections return count of connections

func (*Pool) GetAllConnectedUsers

func (h *Pool) GetAllConnectedUsers() set.GenericDataSet[string]

GetAllConnectedUsers get all connected users

func (*Pool) Handler

func (h *Pool) Handler(w http.ResponseWriter, r *http.Request)

Handler listen for messages

func (*Pool) Remove

func (h *Pool) Remove(userID string)

Remove remove connection

func (*Pool) Send

func (h *Pool) Send(userID string, msg Message) error

Send send message to all connections

func (*Pool) SendToAll

func (h *Pool) SendToAll(msg Message)

SendToAll send message to all connections

func (*Pool) StopAll

func (h *Pool) StopAll()

StopAll stop all connections

Jump to

Keyboard shortcuts

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