forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenrtb_util.go
61 lines (50 loc) · 1.43 KB
/
openrtb_util.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
package adapters
import (
"encoding/json"
"errors"
"fmt"
"github.com/mxmCherry/openrtb/v15/openrtb2"
"github.com/prebid/prebid-server/openrtb_ext"
)
func ExtractAdapterReqBidderParams(bidRequest *openrtb2.BidRequest) (map[string]json.RawMessage, error) {
if bidRequest == nil {
return nil, errors.New("error bidRequest should not be nil")
}
reqExt := &openrtb_ext.ExtRequest{}
if len(bidRequest.Ext) > 0 {
err := json.Unmarshal(bidRequest.Ext, &reqExt)
if err != nil {
return nil, fmt.Errorf("error decoding Request.ext : %s", err.Error())
}
}
if reqExt.Prebid.BidderParams == nil {
return nil, nil
}
var bidderParams map[string]json.RawMessage
err := json.Unmarshal(reqExt.Prebid.BidderParams, &bidderParams)
if err != nil {
return nil, err
}
return bidderParams, nil
}
func ExtractReqExtBidderParams(bidReq *openrtb2.BidRequest) (map[string]map[string]json.RawMessage, error) {
if bidReq == nil {
return nil, errors.New("error bidRequest should not be nil")
}
reqExt := &openrtb_ext.ExtRequest{}
if len(bidReq.Ext) > 0 {
err := json.Unmarshal(bidReq.Ext, &reqExt)
if err != nil {
return nil, fmt.Errorf("error decoding Request.ext : %s", err.Error())
}
}
if reqExt.Prebid.BidderParams == nil {
return nil, nil
}
var bidderParams map[string]map[string]json.RawMessage
err := json.Unmarshal(reqExt.Prebid.BidderParams, &bidderParams)
if err != nil {
return nil, err
}
return bidderParams, nil
}