-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.go
52 lines (43 loc) · 1.11 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package go_websocket
import (
"github.com/bwmarrin/snowflake"
"github.com/gorilla/websocket"
"strconv"
"time"
)
const (
// Time allowed to write a message to the peer.
writeWait = 10 * time.Second
// Time allowed to read the next pong message from the peer.
pongWait = 60 * time.Second
// Send pings to peer with this period. Must be less than pongWait.
pingPeriod = (pongWait * 9) / 10
// Maximum message size allowed from peer.
maxMessageSize = 5012
readBufferSize = 1024 // 读缓冲区大小
writeBufferSize = 1024 // 写缓冲区大小
)
var (
newline = []byte{'\n'}
space = []byte{' '}
)
type Client struct {
ClientId string `json:"client_id"` // 客户端连接ID
GroupId string `json:"group_id"` // 群组id
SystemId string `json:"system_id"` // 系统ID 为分布式做准备的
Conn *websocket.Conn
send chan []byte
hub *Hub
}
// GenerateUuid 生成唯一ID
func GenerateUuid(node *snowflake.Node) string {
if node == nil {
var err error
node, err = snowflake.NewNode(1)
if err != nil {
return ""
}
}
id := node.Generate()
return strconv.FormatInt(id.Int64(), 10)
}