wscore

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UpWebsocket = websocket.Upgrader{

	ReadBufferSize: 1024 * 1024,

	WriteBufferSize: 1024 * 1024,

	EnableCompression: false,

	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

Functions

func KeepaliveMessage

func KeepaliveMessage() []byte

func KeepaliveNull

func KeepaliveNull() []byte

func ServeHome

func ServeHome(w http.ResponseWriter, r *http.Request)

Types

type Client

type Client struct {
	Options *ClientOptions

	//request 请求上下文
	Ctx IRequest
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conf *gofkConfs.WsConfig, conn *websocket.Conn, handle IMsgHandler, opts ...ClientOption) *Client

func (*Client) GetUUid

func (c *Client) GetUUid() string

func (*Client) Start

func (c *Client) Start(hub *Hub)

func (*Client) Stop

func (c *Client) Stop(hub *Hub)

type ClientOption

type ClientOption func(options *ClientOptions)

type ClientOptions

type ClientOptions struct {
	// contains filtered or unexported fields
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub(conf *gofkConfs.WsConfig) *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast() chan []byte

func (*Hub) Clients

func (h *Hub) Clients() *sync.Map

func (*Hub) Conf

func (h *Hub) Conf() *gofkConfs.WsConfig

func (*Hub) RegisterAdd

func (h *Hub) RegisterAdd(cli *Client)

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) SessionLength

func (h *Hub) SessionLength() int64

func (*Hub) UnRegister

func (h *Hub) UnRegister() chan *Client

type IMsgHandler

type IMsgHandler interface {

	//DoMsgHandler 调度执行路由器,调度/执行对应的Rpc消息处理方法
	DoMsgHandler(request IRequest) IResponse

	//AddRouter 添加路由器,为消息添加具体的处理业务逻辑
	AddRouter(method string, router IRouter)
}

type IRequest

type IRequest interface {
	Message() event.IMessage
	SetMessage(message event.IMessage)

	Router() IMsgHandler

	Conn() *websocket.Conn
}

func NewRequest

func NewRequest(opts ...RequestOptionFunc) IRequest

type IResponse

type IResponse []byte

type IRouter

type IRouter func(ctx context.Context, request []byte, opts ...grpc.CallOption) (interface{}, error)

type MsgHandler

type MsgHandler struct {

	// method 协议对应的 router 路由,到rpc服务
	MethodMap map[string]IRouter
}

func NewMsgHandler

func NewMsgHandler() *MsgHandler

func (*MsgHandler) AddRouter

func (m *MsgHandler) AddRouter(method string, router IRouter)

AddRouter 2.添加路由器,为消息添加具体的处理业务逻辑

func (*MsgHandler) DoMsgHandler

func (m *MsgHandler) DoMsgHandler(request IRequest) IResponse

DoMsgHandler 1.调度执行路由器,调度/执行对应的Router消息处理方法

type RequestOptionFunc

type RequestOptionFunc func(options *requestOptions)

func WithHandler

func WithHandler(handler IMsgHandler) RequestOptionFunc

func WithMessage

func WithMessage(msg event.IMessage) RequestOptionFunc

func WithWsConnect

func WithWsConnect(conn *websocket.Conn) RequestOptionFunc

Jump to

Keyboard shortcuts

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