forked from getblank/wango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wango.go
88 lines (79 loc) · 1.64 KB
/
wango.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package wango
import (
"errors"
"fmt"
"time"
"github.com/getblank/uuid"
)
const (
msgWelcome = iota
msgPrefix
msgCall
msgCallResult
msgCallError
msgSubscribe
msgUnsubscribe
msgPublish
msgEvent
msgSubscribed
msgSubscribeError
msgUnsubscribed
msgUnsubscribeError
msgHeartbeat = 20
)
const (
hbLimit = 5
hbTimeout = time.Second * 5
sendChanBufferSize = 50
identity = "wango"
subscriberExists = true
)
var (
msgIntTypes = map[int]string{
0: "WELCOME",
1: "PREFIX",
2: "CALL",
3: "CALLRESULT",
4: "CALLERROR",
5: "SUBSCRIBE",
6: "UNSUBSCRIBE",
7: "PUBLISH",
8: "EVENT",
9: "SUBSCRIBED",
10: "SUBSCRIBEERROR",
11: "UNSUBSCRIBED",
12: "UNSUBSCRIBEERROR",
20: "HB",
}
msgTxtTypes = map[string]int{
"WELCOME": 0,
"PREFIX": 1,
"CALL": 2,
"CALLRESULT": 3,
"CALLERROR": 4,
"SUBSCRIBE": 5,
"UNSUBSCRIBE": 6,
"PUBLISH": 7,
"EVENT": 8,
"SUBSCRIBED": 9,
"SUBSCRIBEERROR": 10,
"UNSUBSCRIBED": 11,
"UNSUBSCRIBEERROR": 12,
"HB": 20,
}
errHandlerAlreadyRegistered = errors.New("Handler already registered")
errRPCNotRegistered = errors.New("RPC not registered")
errSubURINotRegistered = errors.New("Sub URI not registered")
errForbidden = errors.New("403 forbidden")
errNotSubscribes = errors.New("Not subscribed")
errConnectionClosed = errors.New("Connection closed")
debugMode bool
)
func newUUIDv4() string {
return uuid.NewV4()
}
func logger(in ...interface{}) {
if debugMode {
fmt.Println(in...)
}
}