forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschain.go
27 lines (21 loc) · 832 Bytes
/
schain.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
package schain
import (
"fmt"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/openrtb_ext"
)
// BidderToPrebidSChains organizes the ORTB 2.5 multiple root schain nodes into a map of schain nodes by bidder
func BidderToPrebidSChains(sChains []*openrtb_ext.ExtRequestPrebidSChain) (map[string]*openrtb2.SupplyChain, error) {
bidderToSChains := make(map[string]*openrtb2.SupplyChain)
for _, schainWrapper := range sChains {
for _, bidder := range schainWrapper.Bidders {
if _, present := bidderToSChains[bidder]; present {
return nil, fmt.Errorf("request.ext.prebid.schains contains multiple schains for bidder %s; "+
"it must contain no more than one per bidder.", bidder)
} else {
bidderToSChains[bidder] = &schainWrapper.SChain
}
}
}
return bidderToSChains, nil
}