Documentation
¶
Index ¶
- type ConcurrentMap
- func (c *ConcurrentMap) Delete(key interface{})
- func (c *ConcurrentMap) Len() int
- func (c *ConcurrentMap) Load(key interface{}) (value interface{}, exist bool)
- func (c *ConcurrentMap) Range(f func(key interface{}, value interface{}) bool)
- func (c *ConcurrentMap) Store(key interface{}, value interface{})
- type Conn
- func (c *Conn) Close(code uint16, reason []byte)
- func (c *Conn) Listen()
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) NetConn() net.Conn
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time)
- func (c *Conn) SetReadDeadline(t time.Time)
- func (c *Conn) SetWriteDeadline(t time.Time)
- func (c *Conn) WriteMessage(opcode Opcode, payload []byte)
- func (c *Conn) WritePing(payload []byte)
- func (c *Conn) WritePong(payload []byte)
- func (c *Conn) WriteString(s string)
- type Event
- type Map
- type Message
- type Opcode
- type Option
- func WithCheckOrigin(f func(r *Request) bool) Option
- func WithCheckTextEncoding(check bool) Option
- func WithCompress(enabled bool, level int) Option
- func WithEventHandler(eventHandler Event) Option
- func WithInitialize() Option
- func WithMaxContentLength(n int) Option
- func WithResponseHeader(h http.Header) Option
- type Request
- type SessionStorage
- type Upgrader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶ added in v1.2.5
type ConcurrentMap struct {
// contains filtered or unexported fields
}
ConcurrentMap used to store websocket connections in the IM server 用来存储IM等服务的连接
func NewConcurrentMap ¶ added in v1.2.5
func NewConcurrentMap(segments uint64) *ConcurrentMap
func (*ConcurrentMap) Delete ¶ added in v1.2.5
func (c *ConcurrentMap) Delete(key interface{})
func (*ConcurrentMap) Len ¶ added in v1.2.5
func (c *ConcurrentMap) Len() int
func (*ConcurrentMap) Load ¶ added in v1.2.5
func (c *ConcurrentMap) Load(key interface{}) (value interface{}, exist bool)
func (*ConcurrentMap) Range ¶ added in v1.2.5
func (c *ConcurrentMap) Range(f func(key interface{}, value interface{}) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (*ConcurrentMap) Store ¶ added in v1.2.5
func (c *ConcurrentMap) Store(key interface{}, value interface{})
type Conn ¶
type Conn struct {
// store session information
SessionStorage SessionStorage
// contains filtered or unexported fields
}
func (*Conn) Close ¶
Close proactively close the connection code: https://developer.mozilla.org/zh-CN/docs/Web/API/CloseEvent#status_codes 主动关闭连接, 发送关闭帧, 并将连接状态置为关闭
func (*Conn) Listen ¶ added in v1.1.2
func (c *Conn) Listen()
Listen listening to websocket messages through a dead loop 监听websocket消息
func (*Conn) RemoteAddr ¶ added in v1.0.1
func (*Conn) SetReadDeadline ¶ added in v1.1.2
SetReadDeadline sets read deadline
func (*Conn) SetWriteDeadline ¶ added in v1.1.2
SetWriteDeadline sets write deadline
func (*Conn) WriteMessage ¶ added in v1.1.0
WriteMessage write text/binary message text message must be utf8 encoding 发送文本/二进制消息, 文本消息必须是utf8编码
func (*Conn) WriteString ¶ added in v1.2.10
WriteString write text frame
type Event ¶ added in v1.1.2
type Event interface {
OnOpen(socket *Conn)
OnError(socket *Conn, err error)
OnClose(socket *Conn, code uint16, reason []byte)
OnPing(socket *Conn, payload []byte)
OnPong(socket *Conn, payload []byte)
OnMessage(socket *Conn, message *Message)
}
WebSocket Event one of onclose and onerror will be called once during the connection's lifetime. 在连接的生命周期中,onclose和onerror中的一个有且只有一次被调用
type Map ¶ added in v1.2.3
type Map struct {
// contains filtered or unexported fields
}
func (*Map) Delete ¶ added in v1.2.3
func (c *Map) Delete(key interface{})
Delete deletes the value for a key.
type Option ¶ added in v1.2.11
type Option func(c *Upgrader)
func WithCheckOrigin ¶ added in v1.2.11
WithCheckOrigin check request origin
func WithCheckTextEncoding ¶ added in v1.2.11
WithCheckTextEncoding set text encoding checking
func WithCompress ¶ added in v1.2.11
WithCompress set deflate compress
func WithEventHandler ¶ added in v1.2.11
WithEventHandler set event handler
func WithInitialize ¶ added in v1.2.11
func WithInitialize() Option
WithInitialize initialize the upgrader configure
func WithMaxContentLength ¶ added in v1.2.11
WithMaxContentLength set max content length
func WithResponseHeader ¶ added in v1.2.11
WithResponseHeader set response header client may not support, use nil instead
type Request ¶
type Request struct {
*http.Request // http request
SessionStorage SessionStorage // store user session
}
type SessionStorage ¶ added in v1.2.3
type SessionStorage interface {
Load(key interface{}) (value interface{}, exist bool)
Delete(key interface{})
Store(key interface{}, value interface{})
Range(f func(key, value interface{}) bool)
}
SessionStorage because sync.Map is not easy to debug, so I implemented my own map. if you don't like it, you can also use sync.Map instead.
type Upgrader ¶
type Upgrader struct {
// websocket event handler
EventHandler Event
// whether to compress data
CompressEnabled bool
// compress level eg: flate.BestSpeed
CompressLevel int
// max message size
MaxContentLength int
// whether to check utf8 encoding, disabled for better performance
CheckTextEncoding bool
// https://www.rfc-editor.org/rfc/rfc6455.html#section-1.3
// attention: client may not support custom response header, use nil instead
ResponseHeader http.Header
// client authentication
CheckOrigin func(r *Request) bool
}
Upgrader websocket upgrader do not use &Upgrader unless, some options may not be initialized NewUpgrader is recommended