Documentation
¶
Index ¶
- Variables
- type Code
- type Conn
- func (c *Conn) Close(code Code, reason []byte) error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(d time.Duration) error
- func (c *Conn) Write(messageType Opcode, content []byte)
- func (c *Conn) WritePing(payload []byte)
- func (c *Conn) WritePong(payload []byte)
- type EventHandler
- type HandlerFunc
- type Message
- type Opcode
- type Request
- type ServerOptions
- type Upgrader
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ERR_CheckOrigin = errors.New("check origin error") ERR_WebSocketHandshake = errors.New("websocket handshake error") )
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code uint16
const ( // 正常关闭; 无论为何目的而创建, 该链接都已成功完成任务. CloseNormalClosure Code = 1000 // 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开. CloseGoingAway Code = 1001 // 由于协议错误而中断连接. CloseProtocolError Code = 1002 // 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据). CloseUnsupported Code = 1003 // 保留. 表示没有收到预期的状态码. CloseNoStatusReceived Code = 1005 // 保留. 用于期望收到状态码时连接非正常关闭 (也就是说, 没有发送关闭帧). CloseAbnormalClosure Code = 1006 // 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据). CloseUnsupportedData Code = 1007 // 由于收到不符合约定的数据而断开连接. 这是一个通用状态码, 用于不适合使用 1003 和 1009 状态码的场景. ClosePolicyViolation Code = 1008 // 由于收到过大的数据帧而断开连接. CloseMessageTooLarge Code = 1009 // 客户端期望服务器商定一个或多个拓展, 但服务器没有处理, 因此客户端断开连接. CloseMissingExtension Code = 1010 // 客户端由于遇到没有预料的情况阻止其完成请求, 因此服务端断开连接. CloseInternalServerErr Code = 1011 // 服务器由于重启而断开连接. [Ref] CloseServiceRestart Code = 1012 // 服务器由于临时原因断开连接, 如服务器过载因此断开一部分客户端连接. [Ref] CloseTryAgainLater Code = 1013 // 保留. 表示连接由于无法完成 TLS 握手而关闭 (例如无法验证服务器证书). CloseTLSHandshake Code = 1015 )
type Conn ¶
type Conn struct {
// context
Context context.Context
// store session information
Storage *internal.Map
// contains filtered or unexported fields
}
func (*Conn) RemoteAddr ¶ added in v1.0.1
func (*Conn) SetDeadline ¶
set connection deadline
type EventHandler ¶
type HandlerFunc ¶
func RateLimiter ¶ added in v1.0.1
func RateLimiter(d time.Duration, n int64) HandlerFunc
global rate limiter if d=1min and n=100, max speed is 100/min
func Recovery ¶ added in v1.0.1
func Recovery(exceptionHandler func(exception interface{})) HandlerFunc
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
func NewMessage ¶
func (*Message) MessageType ¶
type ServerOptions ¶
type ServerOptions struct {
// whether to show error log, dv=true
LogEnabled bool
// whether to compress data, dv = false
CompressEnabled bool
// compress level eg: flate.BestSpeed
CompressLevel int
// websocket handshake timeout, dv=3s
HandshakeTimeout time.Duration
// max message length, dv=1024*1024 (1MB)
MaxContentLength int
// number of concurrently processed messages allowed by the connection, dv=4
// Concurrency=pow(2, n), eg: 4, 8, 16...
Concurrency uint8
// read frame timeout, dv=5s
ReadTimeout time.Duration
// write frame timeout, dv=5s
WriteTimeout time.Duration
}
dv means default value
type Upgrader ¶
type Upgrader struct {
*ServerOptions // config
Header http.Header // set response header
CheckOrigin func(r *Request) bool // filter user request
// contains filtered or unexported fields
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.