-
Notifications
You must be signed in to change notification settings - Fork 726
/
json.go
88 lines (76 loc) · 1.84 KB
/
json.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
80
81
82
83
84
85
86
87
88
package helpers
import (
"encoding/json"
"fmt"
"github.com/prebid/prebid-server/analytics"
)
func JsonifyAuctionObject(ao *analytics.AuctionObject, scope string) ([]byte, error) {
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*analytics.AuctionObject
}{
Scope: scope,
AuctionObject: ao,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("auction object badly formed %v", err)
}
func JsonifyVideoObject(vo *analytics.VideoObject, scope string) ([]byte, error) {
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*analytics.VideoObject
}{
Scope: scope,
VideoObject: vo,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("video object badly formed %v", err)
}
func JsonifyCookieSync(cso *analytics.CookieSyncObject, scope string) ([]byte, error) {
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*analytics.CookieSyncObject
}{
Scope: scope,
CookieSyncObject: cso,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("cookie sync object badly formed %v", err)
}
func JsonifySetUIDObject(so *analytics.SetUIDObject, scope string) ([]byte, error) {
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*analytics.SetUIDObject
}{
Scope: scope,
SetUIDObject: so,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("set UID object badly formed %v", err)
}
func JsonifyAmpObject(ao *analytics.AmpObject, scope string) ([]byte, error) {
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*analytics.AmpObject
}{
Scope: scope,
AmpObject: ao,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("amp object badly formed %v", err)
}