forked from getblank/wango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg.go
36 lines (29 loc) · 728 Bytes
/
msg.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
package wango
import "encoding/json"
type wampMsg struct {
ID interface{}
URI string
Args []interface{}
}
func createMessage(args ...interface{}) ([]byte, error) {
return json.Marshal(args)
}
func createHeartbeatEvent(counter int) ([]byte, error) {
return createMessage(msgHeartbeat, counter)
}
func createHeartbeatTxtEvent(counter int) ([]byte, error) {
return createMessage(msgIntTypes[msgHeartbeat], counter)
}
func createWelcomeMessage(id string) ([]byte, error) {
return createMessage(msgIntTypes[msgWelcome], id, 1, identity)
}
func createError(err interface{}) string {
var text string
switch err.(type) {
case error:
text = err.(error).Error()
case string:
text = err.(string)
}
return text
}