-
Notifications
You must be signed in to change notification settings - Fork 6
/
prepare.go
43 lines (36 loc) · 1.14 KB
/
prepare.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
package testhelper
import (
"encoding/json"
"fmt"
)
// PreparePubSubMessagePublishedData modifies data for protojson parsing.
// - Remove fields protojson considers duplicate field names
// - Remove @type properties
func PreparePubSubMessagePublishedData(b []byte) ([]byte, error) {
var j map[string]interface{}
if err := json.Unmarshal(b, &j); err != nil {
return nil, fmt.Errorf("json.Unmarshal: %w", err)
}
m := j["message"].(map[string]interface{})
// Remove reserved @type field.
delete(m, "@type")
// Remove message_id field name conflict with messageId.
delete(m, "message_id")
// Remove publish_time field name conflict with publishTime.
delete(m, "publish_time")
j["message"] = m
return json.Marshal(j)
}
// PrepareAuditLogEntryData modifies data for protojson parsing.
// - Remove @type properties
func PrepareAuditLogEntryData(b []byte) ([]byte, error) {
var j map[string]interface{}
if err := json.Unmarshal(b, &j); err != nil {
return nil, fmt.Errorf("json.Unmarshal: %w", err)
}
m := j["protoPayload"].(map[string]interface{})
// Remove reserved @type field.
delete(m, "@type")
j["protoPayload"] = m
return json.Marshal(j)
}