gcws

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

安装依赖

go get github.com/fasthttp/websocket

Documentation

Index

Constants

View Source
const CmdNameLogin = "login"

Variables

This section is empty.

Functions

func DoCmdAction

func DoCmdAction(c *Client, cmd WSCmd)

func InitWS

func InitWS()

func InitWSX

func InitWSX(addr string, c chan struct{})

func LoginCMDHandler

func LoginCMDHandler(c *Client, cmd WSCmd)

func LoginCmdAction

func LoginCmdAction(c *Client, input LoginCmdInput)

func RegisterCmdHandler

func RegisterCmdHandler(cmd string, handler WSCmdHandler)

Types

type Client

type Client struct {
	Hub *Hub

	// user identify
	ID string
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the Hub.

func (*Client) GetIP

func (c *Client) GetIP() string

func (*Client) SendFailureMsg

func (c *Client) SendFailureMsg(msg string, v ...interface{})

func (*Client) SendFailureMsgWithErr

func (c *Client) SendFailureMsgWithErr(err error)

func (*Client) SendSuccessMsg

func (c *Client) SendSuccessMsg(msg interface{})

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

type LoginCmdInput

type LoginCmdInput struct {
	Name   string `json:"name"`
	Passwd string `json:"passwd"`
}

type WSCmd

type WSCmd struct {
	Cmd      string      `json:"cmd"`      // 命令
	Category string      `json:"category"` // 类型
	Target   string      `json:"target"`   // 目标
	Data     interface{} `json:"data"`     // 命令的内容
}

func ParseCmd

func ParseCmd(bytes []byte) (WSCmd, error)

type WSCmdHandler

type WSCmdHandler func(c *Client, cmd WSCmd)

Jump to

Keyboard shortcuts

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