ws

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GinWebsocketHandler

func GinWebsocketHandler(recieveMessageFunc RecieveMessageFunc, shakeSuccessFunc ShakeSuccessFunc) func(c *gin.Context)

@title ws握手接口 @description 本质来说, WS服务在握手的过程中最开始也是HTTP请求, 然后再 Upgrade 到WS模式的,Upgrade函数接受三个参数, 一个是返回值套接字, 一个是请求套接字, 一个是返回值的头,而对于 Gin 的上下文 gin.Context 来说也是有这些数据的 @param recieveMessageFunc RecieveMessageFunc "服务端收到客户端发送的消息时的处理逻辑" @param shakeSuccessFunc ShakeSuccessFunc "客户端初次握手时的处理逻辑"

Types

type Message

type Message struct {
	WsId       string   `json:"-"`                    // 会话id
	Sender     string   `json:"sender,omitempty"`     // 发件人id -> wsid
	Recipients []string `json:"recipients,omitempty"` // 收件人id -> wsid
	Content    []byte   `json:"content,omitempty"`    // 内容
}

type RecieveMessageFunc

type RecieveMessageFunc func(Message) Message // 接收消息时的业务处理

type ShakeSuccessFunc

type ShakeSuccessFunc func(wsid string, c *gin.Context)

握手成功后,需要进行的业务处理,入参为握手成功的websocket的id和用户上下文

type WSConfig

type WSConfig struct {
	Enable bool `mapstructure:"enable" json:"enable" yaml:"enable"` // 是否开启
}

func (WSConfig) Load

func (c WSConfig) Load()

Jump to

Keyboard shortcuts

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