websocket

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OnConnectHandlers = make([]OnConnectHandler, 0)
	OnCloseHandlers   = make([]OnConnectHandler, 0)
)

路由器的处理映射

Functions

This section is empty.

Types

type Handler

type Handler func(conn *WebsocketData, req any) (err error)

定义一个处理方法的类型

type OnConnectHandler added in v1.2.10

type OnConnectHandler func(conn *WebsocketData)

type SocketInterface

type SocketInterface interface {
	OnConnect(*websocket.Conn)
	OnMessage(*WebsocketData, []byte, int)
	Send(uuid.UUID, []byte) (err error)
	SendAll(data []byte)
	OnClose(conn *websocket.Conn)
}

type SocketV1

type SocketV1 struct {
	Type int `json:"type"`
}

func NewV1

func NewV1() *SocketV1

func (*SocketV1) Load

func (s *SocketV1) Load(serv *ghttp.Server, prefix string)

func (*SocketV1) OnClose

func (s *SocketV1) OnClose(conn *WebsocketData)

OnClose

@Description:
@receiver s
@param conn

func (*SocketV1) OnConnect

func (s *SocketV1) OnConnect(ctx context.Context, conn *websocket.Conn)

OnConnect

@Description:
@receiver s
@param conn

func (*SocketV1) OnMessage

func (s *SocketV1) OnMessage(conn *WebsocketData, req []byte, msgType int)

OnMessage

@Description:
@receiver s
@param msg
@param msgType

func (*SocketV1) RegisterOnClose added in v1.2.10

func (s *SocketV1) RegisterOnClose(_func OnConnectHandler)

func (*SocketV1) RegisterOnConnect added in v1.2.10

func (s *SocketV1) RegisterOnConnect(_func OnConnectHandler)

注册方法,讲长连接登陆方法进行注册

func (*SocketV1) RegisterRouter

func (s *SocketV1) RegisterRouter(cmd int, handler Handler)

注册方法,将某个消息路由器ID和对应的处理方法关联起来

func (*SocketV1) Send

func (s *SocketV1) Send(id uuid.UUID, data []byte) (err error)

Send

@Description:
@receiver s
@param uid
@param data
@return err

func (*SocketV1) SendAll

func (s *SocketV1) SendAll(data []byte)

批量发送

type WebsocketData

type WebsocketData struct {
	Ws   *websocket.Conn
	Uuid uuid.UUID
	Uid  int64
	Ctx  context.Context
}

Jump to

Keyboard shortcuts

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