github.com/prebid/prebid-server/v2@v2.18.0/currency/aggregate_conversions.go (about) 1 package currency 2 3 // AggregateConversions contains both the request-defined currency rate 4 // map found in request.ext.prebid.currency and the currencies conversion 5 // rates fetched with the RateConverter object defined in rate_converter.go 6 // It implements the Conversions interface. 7 type AggregateConversions struct { 8 customRates, serverRates Conversions 9 } 10 11 // NewAggregateConversions expects both customRates and pbsRates to not be nil 12 func NewAggregateConversions(customRates, pbsRates Conversions) *AggregateConversions { 13 return &AggregateConversions{ 14 customRates: customRates, 15 serverRates: pbsRates, 16 } 17 } 18 19 // GetRate returns the conversion rate between two currencies prioritizing 20 // the customRates currency rate over that of the PBS currency rate service 21 // returns an error if both Conversions objects return error. 22 func (re *AggregateConversions) GetRate(from string, to string) (float64, error) { 23 rate, err := re.customRates.GetRate(from, to) 24 if err == nil { 25 return rate, nil 26 } else if _, isMissingRateErr := err.(ConversionNotFoundError); !isMissingRateErr { 27 // other error, return the error 28 return 0, err 29 } 30 31 // because the custom rates' GetRate() call returned an error other than "conversion 32 // rate not found", there's nothing wrong with the 3 letter currency code so let's 33 // try the PBS rates instead 34 return re.serverRates.GetRate(from, to) 35 } 36 37 // GetRates is not implemented for AggregateConversions . There is no need to call 38 // this function for this scenario. 39 func (r *AggregateConversions) GetRates() *map[string]map[string]float64 { 40 return nil 41 }