websockets

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Ctx

type Ctx struct {
	Request  Request
	Response *Response
	Extras   map[string]interface{}
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(msg *websocketspb.ServerMessage) *Ctx

func (*Ctx) ToClientMessage

func (c *Ctx) ToClientMessage() *websocketspb.ClientMessage

func (*Ctx) WithError

func (c *Ctx) WithError(err error)

type EventType

type EventType string
const (
	EventType_Connect    EventType = "connect"
	EventType_Disconnect EventType = "disconnect"
	EventType_Message    EventType = "message"
)

type Request

type Request interface {
	SocketName() string
	EventType() EventType
	ConnectionID() string
	QueryParams() map[string][]string
	Message() string
}

type Response

type Response struct {
	Reject bool
}

type Websocket

type Websocket interface {
	// Name - Get the name of the Websocket API
	Name() string
	// On registers a handler for a specific event type on the websocket
	// Valid function signatures for handler are:
	//
	//	func()
	//	func() error
	//	func(*websocket.Ctx)
	//	func(*websocket.Ctx) error
	//	Handler[websocket.Ctx]
	On(eventType EventType, handler interface{})
	// Send a message to a specific connection
	Send(ctx context.Context, connectionId string, message []byte) error
	// Close a specific connection
	Close(ctx context.Context, connectionId string) error
}

Websocket - Nitric Websocket API Resource

func NewWebsocket

func NewWebsocket(name string) Websocket

NewWebsocket - Create a new Websocket API resource

Jump to

Keyboard shortcuts

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