-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.go
60 lines (52 loc) · 1.39 KB
/
types.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
53
54
55
56
57
58
59
60
package cs
import (
"encoding/json"
)
// 内置命令
const (
// CmdConnected on connection connected
CmdConnected = "__cs_connected__"
// CmdClosed on connection closed
CmdClosed = "__cs_closed__"
// CmdHeartbeat heartbeat message
CmdHeartbeat = "__cs_heartbeat__"
)
// 默认消息
const (
msgOk = "ok"
msgUnsupportCmd = "unsupport cmd"
)
// Request request message
type Request struct {
Cmd string // message command, use for route
Seqno string // seq number,the request id
RawData json.RawMessage // request raw []byte data
}
// Response reply Request message
type Response struct {
*Request // reply the Request
Cmd string // message command, use for route
Seqno string // seq number,the request id
Code int // response status code
Msg string // response status message text
Data interface{} // response data
}
func (r *Response) fill() {
if r.Code == 0 && r.Msg == "" {
r.Msg = msgOk
}
if r.Seqno == "" {
r.Seqno = randomString(12)
}
}
// ServerAdapter defined integer to srv server
type ServerAdapter interface {
// Write send response message to connect
Write(sid string, resp *Response) error
// Read read message form connect
Read(*Srv) (sid string, req *Request, err error)
// Close close specify connect
Close(sid string) error
// GetAllSID get server all sid
GetAllSID() []string
}