gsse

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NoId         = ""
	NoEvent      = ""
	EmptyComment = ""
)

Variables

This section is empty.

Functions

func Handle

func Handle(fn func(*Client)) func(*ghttp.Request)

Handle wraps func(*gsse.Client) to func(*ghttp.Request), use by ghttp.Server.BindHandler().

Types

type Client

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

Client wraps the SSE(Server-Sent Event) ghttp.Request and provides SSE APIs

func (*Client) Close

func (c *Client) Close()

Close closes the connection

func (*Client) Context

func (c *Client) Context() context.Context

Context is alias for ghttp.Request.Context().

func (*Client) KeepAlive

func (c *Client) KeepAlive()

KeepAlive keeps the connection alive, if you need to use the client outside the handler

func (*Client) OnClose

func (c *Client) OnClose(fn func(*Client))

OnClose callback which runs when a client closes its connection

func (*Client) Request

func (c *Client) Request() *ghttp.Request

Request return ghttp.Request.

func (*Client) Response

func (c *Client) Response() *ghttp.Response

Response is alias for ghttp.Request.Response.

func (*Client) SendComment

func (c *Client) SendComment(comment ...string)

SendComment send comment with prefix":"

func (*Client) SendEvent

func (c *Client) SendEvent(event string, data ...string)

SendEvent calls emit(NoId, event, data...)

func (*Client) SendEventWithId

func (c *Client) SendEventWithId(id, event string, data ...string)

SendEventWithId calls emit(id, event, data...)

func (*Client) SendMessage

func (c *Client) SendMessage(data ...string)

SendMessage calls emit(NoId, NoEvent, data...)

func (*Client) SendMessageWithId

func (c *Client) SendMessageWithId(id string, data ...string)

SendMessageWithId calls emit(id, NoEvent, data...)

func (*Client) Terminated

func (c *Client) Terminated() bool

Terminated returns true if the connection has been closed

Jump to

Keyboard shortcuts

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