-
Notifications
You must be signed in to change notification settings - Fork 718
/
json.go
161 lines (144 loc) · 3.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package helpers
import (
"encoding/json"
"fmt"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/analytics"
)
func JsonifyAuctionObject(ao *analytics.AuctionObject, scope string) ([]byte, error) {
var logEntry *logAuction
if ao != nil {
var request *openrtb2.BidRequest
if ao.RequestWrapper != nil {
request = ao.RequestWrapper.BidRequest
}
logEntry = &logAuction{
Status: ao.Status,
Errors: ao.Errors,
Request: request,
Response: ao.Response,
Account: ao.Account,
StartTime: ao.StartTime,
HookExecutionOutcome: ao.HookExecutionOutcome,
}
}
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*logAuction
}{
Scope: scope,
logAuction: logEntry,
})
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) {
var logEntry *logVideo
if vo != nil {
var request *openrtb2.BidRequest
if vo.RequestWrapper != nil {
request = vo.RequestWrapper.BidRequest
}
logEntry = &logVideo{
Status: vo.Status,
Errors: vo.Errors,
Request: request,
Response: vo.Response,
VideoRequest: vo.VideoRequest,
VideoResponse: vo.VideoResponse,
StartTime: vo.StartTime,
}
}
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*logVideo
}{
Scope: scope,
logVideo: logEntry,
})
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) {
var logEntry *logUserSync
if cso != nil {
logEntry = &logUserSync{
Status: cso.Status,
Errors: cso.Errors,
BidderStatus: cso.BidderStatus,
}
}
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*logUserSync
}{
Scope: scope,
logUserSync: logEntry,
})
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) {
var logEntry *logSetUID
if so != nil {
logEntry = &logSetUID{
Status: so.Status,
Bidder: so.Bidder,
UID: so.UID,
Errors: so.Errors,
Success: so.Success,
}
}
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*logSetUID
}{
Scope: scope,
logSetUID: logEntry,
})
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) {
var logEntry *logAMP
if ao != nil {
var request *openrtb2.BidRequest
if ao.RequestWrapper != nil {
request = ao.RequestWrapper.BidRequest
}
logEntry = &logAMP{
Status: ao.Status,
Errors: ao.Errors,
Request: request,
AuctionResponse: ao.AuctionResponse,
AmpTargetingValues: ao.AmpTargetingValues,
Origin: ao.Origin,
StartTime: ao.StartTime,
HookExecutionOutcome: ao.HookExecutionOutcome,
}
}
b, err := json.Marshal(&struct {
Scope string `json:"scope"`
*logAMP
}{
Scope: scope,
logAMP: logEntry,
})
if err == nil {
b = append(b, byte('\n'))
return b, nil
}
return nil, fmt.Errorf("amp object badly formed %v", err)
}