sseKit

package
v3.0.81 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MessageTypeRaw 对于data,不做任何处理
	MessageTypeRaw = &messageType{
		"raw",
	}

	// MessageTypeBase64 对于data,base64编码一下(前端需对应处理)
	MessageTypeBase64 = &messageType{
		"base64",
	}
)

Functions

func IsSseSupported

func IsSseSupported(w http.ResponseWriter, r *http.Request) error

IsSseSupported

@return 为"": 支持SSE

func NewProcessor

func NewProcessor(idGenerator func() (string, error), listener pushKit.Listener, msgType *messageType, pongInterval time.Duration) (pushKit.Processor, error)

NewProcessor

!!!: 需要先调用 pushKit.MustSetUp 或 pushKit.SetUp.

@param idGenerator 可以为nil(将使用xid) @param listener 不能为nil @param msgType 消息类型 @param pongInterval pong的周期(<=0则不发送pong)

func SetHeaders

func SetHeaders(w http.ResponseWriter)

SetHeaders 设置response header.

Types

type Event

type Event sse.Event

func (Event) Push

func (e Event) Push(w http.ResponseWriter) error

type MessageEvent deprecated

type MessageEvent struct {
	// Id
	/*
		PS:
		(1) 对应前端的 e.lastEventId.
		(2) 可以为"".
	*/
	Id string

	// Event
	/*
		PS:
		(1) 对应前端的 e.type.
		(2) 可以为""(此时等价于"message")
		(3) 如果不是 "message" 的话,前端需要自行添加对应的监听.
	*/
	Event string

	// Data
	/*
		PS:
		(1) 对应前端的 e.data.
		(2) 可以为"".
		(3) 建议对内容编码下,以防其中有特殊字符(\n等).
	*/
	Data string
}

MessageEvent 定义SSE事件.

Deprecated: Use sse.Event of github.com/gin-contrib/sse instead.

func (MessageEvent) String

func (e MessageEvent) String() string

String 实现SSE事件的 String() 方法

type SseChannel

type SseChannel struct {
	pushKit.BaseChannel
	// contains filtered or unexported fields
}

func (*SseChannel) Close

func (channel *SseChannel) Close(reason string) error

Close (写锁)后端主动关闭通道.

func (*SseChannel) Initialize

func (channel *SseChannel) Initialize() error

func (*SseChannel) Push

func (channel *SseChannel) Push(data []byte) error

Push (写锁)推送消息给客户端.

func (*SseChannel) PushMessage

func (channel *SseChannel) PushMessage(msgType *messageType, data []byte) (err error)

PushMessage (写锁)推送消息给客户端.

Jump to

Keyboard shortcuts

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