sse

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DemoHanderFunc added in v0.5.7

func DemoHanderFunc(w http.ResponseWriter, r *http.Request)

DemoHanderFunc time tick SSE

func NewHandler

func NewHandler(h Streamer) http.HandlerFunc

NewHandler returns a HandlerFunc that writes/loop the event to the ResponseWriter.

func SSE added in v0.5.7

func SSE(w http.ResponseWriter, r *http.Request, h Streamer)

SSE proxy to Streamer

func Shutdown added in v0.4.2

func Shutdown(w http.ResponseWriter, f http.Flusher) error

Shutdown send shutdown event to client

Types

type Event

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

Event a single event in SSE stream using json marshal encoding

func NewEvent

func NewEvent(name string, data any) Event

NewEvent creates a new SSE event.

func NewMessage

func NewMessage(data any) Event

NewMessage is a special Event using a single/default message in an SSE stream.

func (Event) Bytes

func (e Event) Bytes() []byte

Bytes marshal the event as a byte slice. Escape '\n' to '\r\n'

func (Event) RawBytes added in v0.5.7

func (e Event) RawBytes() []byte

RawBytes set marshal the event as a byte slice. Escape '\n' to '\r\n'

func (Event) Send added in v0.4.9

func (e Event) Send(w io.Writer, f http.Flusher) error

Send syntax sugar

func (Event) SendRaw added in v0.5.7

func (e Event) SendRaw(w io.Writer, f http.Flusher) error

SendRaw syntax sugar

type MsgHandle added in v0.4.7

type MsgHandle func(http.ResponseWriter, http.Flusher, any) error

MsgHandle handle a signal message

type Streamer added in v0.4.9

type Streamer interface {
	Send(context.Context, http.ResponseWriter, http.Flusher)
}

Streamer write endless events to ResponseWriter.

Jump to

Keyboard shortcuts

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