github.com/prebid/prebid-server/v2@v2.18.0/exchange/seat_non_bids.go (about)

     1  package exchange
     2  
     3  import (
     4  	"github.com/prebid/prebid-server/v2/exchange/entities"
     5  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     6  )
     7  
     8  type nonBids struct {
     9  	seatNonBidsMap map[string][]openrtb_ext.NonBid
    10  }
    11  
    12  // addBid is not thread safe as we are initializing and writing to map
    13  func (snb *nonBids) addBid(bid *entities.PbsOrtbBid, nonBidReason int, seat string) {
    14  	if bid == nil || bid.Bid == nil {
    15  		return
    16  	}
    17  	if snb.seatNonBidsMap == nil {
    18  		snb.seatNonBidsMap = make(map[string][]openrtb_ext.NonBid)
    19  	}
    20  	nonBid := openrtb_ext.NonBid{
    21  		ImpId:      bid.Bid.ImpID,
    22  		StatusCode: nonBidReason,
    23  		Ext: openrtb_ext.NonBidExt{
    24  			Prebid: openrtb_ext.ExtResponseNonBidPrebid{Bid: openrtb_ext.NonBidObject{
    25  				Price:          bid.Bid.Price,
    26  				ADomain:        bid.Bid.ADomain,
    27  				CatTax:         bid.Bid.CatTax,
    28  				Cat:            bid.Bid.Cat,
    29  				DealID:         bid.Bid.DealID,
    30  				W:              bid.Bid.W,
    31  				H:              bid.Bid.H,
    32  				Dur:            bid.Bid.Dur,
    33  				MType:          bid.Bid.MType,
    34  				OriginalBidCPM: bid.OriginalBidCPM,
    35  				OriginalBidCur: bid.OriginalBidCur,
    36  			}},
    37  		},
    38  	}
    39  
    40  	snb.seatNonBidsMap[seat] = append(snb.seatNonBidsMap[seat], nonBid)
    41  }
    42  
    43  func (snb *nonBids) get() []openrtb_ext.SeatNonBid {
    44  	if snb == nil {
    45  		return nil
    46  	}
    47  	var seatNonBid []openrtb_ext.SeatNonBid
    48  	for seat, nonBids := range snb.seatNonBidsMap {
    49  		seatNonBid = append(seatNonBid, openrtb_ext.SeatNonBid{
    50  			Seat:   seat,
    51  			NonBid: nonBids,
    52  		})
    53  	}
    54  	return seatNonBid
    55  }