msg

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package msg is the middle layer of client websocket communication This package is used to standardize websocket message formats with clients

Index

Constants

This section is empty.

Variables

View Source
var ErrMsgHandleNotExist = errors.New("msg handel not exist")

Functions

func ForReadAndHandleJsonMsg

func ForReadAndHandleJsonMsg(reader Reader, conn *websocket.Conn) error

func ReadBytes

func ReadBytes(reader Reader, conn *websocket.Conn) ([]byte, error)

func ReadFile

func ReadFile(reader Reader, conn *websocket.Conn) (io.Reader, error)

func RegisterHandle

func RegisterHandle[T any](reader Reader, msgType MsgType, handler func(data T) error)

func Send

func Send[T any](conn *websocket.Conn, t MsgType, data T) error

func SendError

func SendError(conn *websocket.Conn, err error) error

Types

type Msg

type Msg struct {
	Type MsgType
	Data any
}

type MsgHandler

type MsgHandler func([]byte) error

type MsgType

type MsgType string

type Reader

type Reader interface {
	// contains filtered or unexported methods
}

func NewReader

func NewReader() Reader

Jump to

Keyboard shortcuts

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