ws

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BodyError Message Body map typ for errors
	BodyError = "error"
	// BodySet Message Body map typ for set values
	BodySet = "set"
	// BodyGet Message Body map typ for get values
	BodyGet = "get"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Type       string                 `json:"type"`
	ID         *uuid.UUID             `json:"id,omitempty"`
	ReplyID    *uuid.UUID             `json:"reply_id,omitempty"`
	Body       map[string]interface{} `json:"body"`
	Subscriber *Subscriber            `json:"-"`
}

Message on websocket

func (*Message) Reply

func (m *Message) Reply(msg *Message)

Reply to Message

type MessageHandleFunc

type MessageHandleFunc func(ctx context.Context, msg *Message)

MessageHandleFunc for handling messages

type Subscriber

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

Subscriber of websocket endpoint

type SubscriberEventFunc

type SubscriberEventFunc func(s *Subscriber, msg chan<- *Message)

SubscriberEventFunc for handling connection state of Subsriber

type WebsocketEndpoint

type WebsocketEndpoint struct {
	Subscribers map[*Subscriber]struct{}

	// DefaultMessageHandler if no other handler for MessageType found
	DefaultMessageHandler MessageHandleFunc
	// Run Function on open connection by subscriper
	OnOpen SubscriberEventFunc
	// Run Function on close connection to subscriper
	OnClose SubscriberEventFunc
	// contains filtered or unexported fields
}

WebsocketEndpoint to handle Request

func NewEndpoint

func NewEndpoint(log *zap.Logger) *WebsocketEndpoint

NewEndpoint - create an empty websocket

func (*WebsocketEndpoint) AddMessageHandler

func (we *WebsocketEndpoint) AddMessageHandler(typ string, f MessageHandleFunc)

AddMessageHandler - add websocket message handler

func (*WebsocketEndpoint) Broadcast

func (we *WebsocketEndpoint) Broadcast(msg *Message)

Broadcast Message to all subscriber (exclude sender of Message)

func (*WebsocketEndpoint) Handler

func (we *WebsocketEndpoint) Handler(ctx *gin.Context)

Handler - to register in gin webservice

Jump to

Keyboard shortcuts

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