-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse.go
42 lines (32 loc) · 885 Bytes
/
parse.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
package googlepubsub_adapter
import (
"cloud.google.com/go/pubsub"
"github.com/Aris-haryanto/pubsage/discourse"
)
func parsePublisherToGooglePubsub(message discourse.Publisher) *pubsub.Message {
set := &pubsub.Message{}
set.Data = message.Data
set.OrderingKey = message.GooglePubsub_OrderingKey
attr := map[string]string{}
for k, v := range message.Attributes {
attr[k] = string(v)
}
set.Attributes = attr
return set
}
func parseToMessagePubSage(msg *pubsub.Message) discourse.Message {
set := discourse.Message{}
// set general object struct
set.Data = msg.Data
set.MessageID = msg.ID
set.PublishTime = msg.PublishTime
attr := map[string][]byte{}
for k, v := range msg.Attributes {
attr[k] = []byte(v)
}
set.Attributes = attr
// ==
set.GooglePubsub_DeliveryAttempt = msg.DeliveryAttempt
set.GooglePubsub_OrderingKey = msg.OrderingKey
return set
}