-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmsg.go
79 lines (58 loc) · 1.17 KB
/
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
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
package psub
import (
"strconv"
"cloud.google.com/go/pubsub"
)
type Message struct {
*pubsub.Message
}
const (
_version = "version"
_feature = "feature"
)
func NewMessage(data []byte) *Message {
return &Message{
Message: &pubsub.Message{Data: data},
}
}
func (m *Message) SetVersion(v int) *Message {
if m.Attributes == nil {
m.Attributes = make(map[string]string, 1)
}
m.Attributes[_version] = strconv.Itoa(v)
return m
}
func (m *Message) GetVersion() int {
if m.Attributes == nil {
return 0
}
v, _ := strconv.Atoi(m.Attributes[_version])
return v
}
func (m *Message) SetFeature(f string) *Message {
if m.Attributes == nil {
m.Attributes = make(map[string]string, 1)
}
m.Attributes[_feature] = f
return m
}
func (m *Message) GetFeature() string {
if m.Attributes == nil {
return ""
}
return m.Attributes[_feature]
}
func (m *Message) SetDeliveryOrder(order string) *Message {
m.OrderingKey = order
return m
}
func (m *Message) SetStr(key, value string) *Message {
if m.Attributes == nil {
m.Attributes = make(map[string]string, 1)
}
m.Attributes[key] = value
return m
}
func (m *Message) Get(key string) string {
return m.Attributes[key]
}