@@ -18,57 +18,57 @@ func main() {
18
18
defer db .Close ()
19
19
20
20
// Use Entry.WithPayload() method to bulk store messages as topic is parsed one time on first request.
21
- topic := []byte ("teams.alpha. ch1.r1 " )
21
+ topic := []byte ("teams.private.sales. ch1.message " )
22
22
entry := & unitdb.Entry {Topic : topic }
23
23
for j := 0 ; j < 50 ; j ++ {
24
- db .PutEntry (entry .WithPayload ([]byte (fmt .Sprintf ("msg for team alpha channel1 recipient1 #%2d" , j ))))
24
+ db .PutEntry (entry .WithPayload ([]byte (fmt .Sprintf ("msg for sales team channel1 #%2d" , j ))))
25
25
}
26
26
27
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha. ch1.r1 ?last=1h" )).WithLimit (100 )); err == nil {
27
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales. ch1.message ?last=1h" )).WithLimit (100 )); err == nil {
28
28
for _ , msg := range msgs {
29
29
log .Printf ("%s " , msg )
30
30
}
31
31
}
32
32
33
33
// Writing to single topic in a batch
34
34
err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
35
- topic := []byte ("teams.alpha.ch1.* ?ttl=1h" )
36
- b .Put (topic , []byte ("msg for team alpha channel1 all recipients " ))
35
+ topic := []byte ("teams.private.sales.*.message ?ttl=1h" )
36
+ b .Put (topic , []byte ("msg for sales team all channels " ))
37
37
return nil
38
38
})
39
39
if err != nil {
40
40
log .Fatal (err )
41
41
return
42
42
}
43
43
44
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r2 ?last=1h" )).WithLimit (10 )); err == nil {
44
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
45
45
for _ , msg := range msgs {
46
46
log .Printf ("%s " , msg )
47
47
}
48
48
}
49
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r3 ?last=1h" )).WithLimit (10 )); err == nil {
49
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch3.message ?last=1h" )).WithLimit (10 )); err == nil {
50
50
for _ , msg := range msgs {
51
51
log .Printf ("%s " , msg )
52
52
}
53
53
}
54
54
55
55
// Writing to multiple topics in a batch
56
56
err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
57
- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.ch1.r2 " ), []byte ("msg for team alpha channel1 recipient2 " )))
58
- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.ch1.r3 " ), []byte ("msg for team alpha channel1 recipient3 " )))
57
+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.ch2.message " ), []byte ("msg for sales team channel2 " )))
58
+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.ch3.message " ), []byte ("msg for sales team channel3 " )))
59
59
return nil
60
60
})
61
61
if err != nil {
62
62
log .Fatal (err )
63
63
return
64
64
}
65
65
66
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r2 ?last=1h" )).WithLimit (10 )); err == nil {
66
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
67
67
for _ , msg := range msgs {
68
68
log .Printf ("%s " , msg )
69
69
}
70
70
}
71
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r3 ?last=1h" )).WithLimit (10 )); err == nil {
71
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch3.message ?last=1h" )).WithLimit (10 )); err == nil {
72
72
for _ , msg := range msgs {
73
73
log .Printf ("%s " , msg )
74
74
}
@@ -81,43 +81,43 @@ func main() {
81
81
// Writing to single topic in a batch
82
82
err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
83
83
b .SetOptions (unitdb .WithBatchContract (contract ))
84
- topic := []byte ("teams.alpha.ch1.* ?ttl=1h" )
85
- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #1 " ))
86
- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #2 " ))
87
- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #3 " ))
84
+ topic := []byte ("teams.private.sales.*.message ?ttl=1h" )
85
+ b .Put (topic , []byte ("msg #1 for sales team all channels " ))
86
+ b .Put (topic , []byte ("msg #2 for sales team all channels " ))
87
+ b .Put (topic , []byte ("msg #3 for sales team all channels " ))
88
88
return nil
89
89
})
90
90
91
91
// Writing to multiple topics in a batch
92
92
err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
93
93
b .SetOptions (unitdb .WithBatchContract (contract ))
94
- b .PutEntry (unitdb .NewEntry ([]byte ("teams.*.ch1" ), []byte ("msg for channel1 in any teams" )))
95
- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.* " ), []byte ("msg for all channels in team alpha " )))
96
- b .PutEntry (unitdb .NewEntry ([]byte ("teams... " ), []byte ("msg for all teams and all channels" )))
97
- b .PutEntry (unitdb .NewEntry ([]byte ("..." ), []byte ("msg broadcast to all recipients of all channels in all teams" )))
94
+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private. *.ch1.message " ), []byte ("msg for channel1 in any teams" )))
95
+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.*.message " ), []byte ("msg for all channels in sales team " )))
96
+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private... " ), []byte ("msg for all private teams and all channels" )))
97
+ b .PutEntry (unitdb .NewEntry ([]byte ("..." ), []byte ("msg broadcast to all channels in all teams" )))
98
98
return nil
99
99
})
100
100
if err != nil {
101
101
log .Fatal (err )
102
102
return
103
103
}
104
104
105
- // Get message for team alpha channel1
106
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha. ch1?last=1h" )).WithLimit (10 )); err == nil {
105
+ // Get message for sales team channel1
106
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales. ch1.message ?last=1h" )).WithLimit (10 )); err == nil {
107
107
for _ , msg := range msgs {
108
108
log .Printf ("%s " , msg )
109
109
}
110
110
}
111
111
112
- // Get message for team beta channel1
113
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.beta. ch1?last=1h" )).WithLimit (10 )); err == nil {
112
+ // Get message for customer support team channel1
113
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.public.customersupport. ch1.message ?last=1h" )).WithLimit (10 )); err == nil {
114
114
for _ , msg := range msgs {
115
115
log .Printf ("%s " , msg )
116
116
}
117
117
}
118
118
119
- // Get message for team beta channel2 recipient11
120
- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.beta. ch2.r1 ?last=1h" )).WithLimit (10 )); err == nil {
119
+ // Get message for customer support team channel2
120
+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.public.customersupport. ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
121
121
for _ , msg := range msgs {
122
122
log .Printf ("%s " , msg )
123
123
}
@@ -127,8 +127,8 @@ func main() {
127
127
// Note, encryption can also be set on entire database using DB.Open() and set encryption flag in options parameter.
128
128
err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
129
129
b .SetOptions (unitdb .WithBatchEncryption ())
130
- topic := []byte ("teams.alpha. ch1.r1 ?ttl=1h" )
131
- b .Put (topic , []byte ("msg for team alpha channel1 recipient1 " ))
130
+ topic := []byte ("teams.private.sales. ch1.message ?ttl=1h" )
131
+ b .Put (topic , []byte ("msg for sales team channel1" ))
132
132
return nil
133
133
})
134
134
0 commit comments