websocket

package
v1.2.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(ctx context.Context, req any) (err error)

定义一个处理方法的类型

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{}

func NewV1

func NewV1() *SocketV1

func (*SocketV1) Load

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

func (*SocketV1) OnClose

func (s *SocketV1) OnClose(id uuid.UUID, conn *websocket.Conn)

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) 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