forked from bpowers/radix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
50 lines (43 loc) · 983 Bytes
/
message.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
package redis
import (
"fmt"
)
type MessageType int
const (
MessageSubscribe MessageType = iota
MessageUnsubscribe
MessagePsubscribe
MessagePunsubscribe
MessageMessage
MessagePmessage
)
// Message describes a pub/sub message
type Message struct {
Type MessageType
Channel string
Pattern string
Subscriptions int
Payload string
}
// String returns a string representation of the message.
func (m *Message) String() string {
var mtype string
switch m.Type {
case MessageSubscribe:
mtype = "subscribe"
case MessageUnsubscribe:
mtype = "unsubscribe"
case MessagePsubscribe:
mtype = "psubscribe"
case MessagePunsubscribe:
mtype = "punsubscribe"
case MessageMessage:
mtype = "message"
case MessagePmessage:
mtype = "pmessage"
default:
mtype = "unknown"
}
return fmt.Sprintf("Message{Type: %s, Channel: %v, Pattern: %v, Subscriptions: %v, "+
"Payload: %v}", mtype, m.Channel, m.Pattern, m.Subscriptions, m.Payload)
}