sse

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

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

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 9 Imported by: 1

README

sse

Server-Sent Events support in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateClientID

func GenerateClientID() string

GenerateClientID is used to generate an uuid randomly

Types

type CloseType

type CloseType int

CloseType present the type of closing

const (

	// ClientClose present client initiative to disconnect
	ClientClose CloseType
	// ServerClose present server initiative to disconnect
	ServerClose
)

type Event

type Event struct {
	Event string
	ID    string
	Retry uint
	Data  interface{}
}

Event is the Server-Sent Event data struct

type Option

type Option struct {
	Headers map[string]string
}

Option is used for initialize sse service

type Service

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

Service is the type of sse service instance

func NewService

func NewService() *Service

NewService is used to create a sse.Service instance

func NewServiceWithOption

func NewServiceWithOption(o Option) *Service

NewServiceWithOption is used to create a sse.Service instance with additional option

func (*Service) Broadcast

func (s *Service) Broadcast(e Event)

Broadcast is used to broadcast event to all connected clients

func (*Service) CloseAllClients

func (s *Service) CloseAllClients()

CloseAllClients is used to disconnect all clients

func (*Service) CloseClient

func (s *Service) CloseClient(clientID interface{}) error

CloseClient is used to disconnect client by server

func (*Service) GetClientCount

func (s *Service) GetClientCount() int

GetClientCount is used to get count of client

func (*Service) HandleClient

func (s *Service) HandleClient(clientID interface{}, w http.ResponseWriter) (<-chan CloseType, error)

HandleClient is used to handle a client with streaming and returns a chan of closing

func (*Service) Send

func (s *Service) Send(clientID interface{}, e Event) error

Send is used to send data to client

Jump to

Keyboard shortcuts

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