github.com/prebid/prebid-server/v2@v2.18.0/hooks/hookstage/rawbidderresponse_mutations.go (about) 1 package hookstage 2 3 import ( 4 "errors" 5 6 "github.com/prebid/prebid-server/v2/adapters" 7 ) 8 9 func (c *ChangeSet[T]) RawBidderResponse() ChangeSetRawBidderResponse[T] { 10 return ChangeSetRawBidderResponse[T]{changeSet: c} 11 } 12 13 type ChangeSetRawBidderResponse[T any] struct { 14 changeSet *ChangeSet[T] 15 } 16 17 func (c ChangeSetRawBidderResponse[T]) Bids() ChangeSetBids[T] { 18 return ChangeSetBids[T]{changeSetRawBidderResponse: c} 19 } 20 21 func (c ChangeSetRawBidderResponse[T]) castPayload(p T) (RawBidderResponsePayload, error) { 22 if payload, ok := any(p).(RawBidderResponsePayload); ok { 23 return payload, nil 24 } 25 return RawBidderResponsePayload{}, errors.New("failed to cast RawBidderResponsePayload") 26 } 27 28 type ChangeSetBids[T any] struct { 29 changeSetRawBidderResponse ChangeSetRawBidderResponse[T] 30 } 31 32 func (c ChangeSetBids[T]) Update(bids []*adapters.TypedBid) { 33 c.changeSetRawBidderResponse.changeSet.AddMutation(func(p T) (T, error) { 34 bidderPayload, err := c.changeSetRawBidderResponse.castPayload(p) 35 if err == nil { 36 bidderPayload.Bids = bids 37 } 38 if payload, ok := any(bidderPayload).(T); ok { 39 return payload, nil 40 } 41 return p, errors.New("failed to cast RawBidderResponsePayload") 42 }, MutationUpdate, "bids") 43 }