common

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WriteWait Time allowed to write a message to the peer.
	WriteWait = 60 * time.Second

	// PongWait Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second

	// HeartBeatStep Send pings to peer with this period. Must be less than pongWait.
	//PingPeriod = (PongWait * 9) / 10
	HeartBeatStep = 10 * time.Second

	// MaxMessageSize Maximum message size allowed from peer.
	MaxMessageSize = 65535

	MsgTimeout = 5

	Stop = 1

	PaddingPackageLength = 4
)

Variables

Functions

func FindRemainder

func FindRemainder(dataLength int) int

func Signature

func Signature(data string, remainder int) string

Types

type HeartBeat

type HeartBeat struct {
	StopChan chan int8
}

type Message

type Message struct {
	Code      WsCode `json:"code"`
	Data      string `json:"data"`
	Message   string `json:"message"`
	Timestamp int64  `json:"timestamp"`
}

func PingMessage

func PingMessage() *Message

func (*Message) Decode

func (p *Message) Decode(b []byte) error

func (*Message) Encode

func (p *Message) Encode() ([]byte, error)

type OperateMessage

type OperateMessage struct {
	Operate int         `json:"operate"`
	Data    interface{} `json:"data"`
}

type WsCode

type WsCode int
const (
	CodeHeartBeat WsCode = 100 // 心跳
	CodeWsSuccess WsCode = 200 // 成功
	CodeWsFailure WsCode = 400 // 失败

	WsTimeOut            WsCode = 4000 // timeout
	WsInvalidAccess      WsCode = 4001 // invalid access
	WsServerClose        WsCode = 4002 // server close
	WsInvalidOperateCode WsCode = 4003 // invalid operate

	WsPackageError          WsCode = 4100 // 消息解析错误
	WsPackageWrongPrefix    WsCode = 4101 // 前缀不对
	WsPackageWrongSignature WsCode = 4102 // 签名不对
	WsPackageWrongLength    WsCode = 4103 // 数据长度不对
	WsPackageWrongTime      WsCode = 4104 // 时间不对

	OPCodeWsDownloadQuery   WsCode = 6800 // 查询
	OPCodeWsDownloading     WsCode = 6801 // 下载
	OPCodeWsDownloadCorrect WsCode = 6802 // 校正
	OPCodeWsDownloadFinish  WsCode = 6803 // 完成
	OPCodeWsDownloadTimeout WsCode = 6804 // 超时未响应
)

func (WsCode) String

func (i WsCode) String() string

Jump to

Keyboard shortcuts

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