Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstantRates ¶
type ConstantRates struct{}
ConstantRates doesn't do any currency conversions and accepts only conversions where both currencies (from and to) are the same. If not the same currencies, it returns an error.
func NewConstantRates ¶
func NewConstantRates() *ConstantRates
NewConstantRates creates a new ConstantRates object holding currencies rates
type Conversions ¶
type Conversions interface { GetRate(from string, to string) (float64, error) GetRates() *map[string]map[string]float64 }
Conversions allows to get a conversion rate between two currencies. if one of the currency string is not a currency or if there is not conversion between those currencies, then an err is returned and rate is 0.
type ConverterInfo ¶
type ConverterInfo interface { Source() string LastUpdated() time.Time Rates() *map[string]map[string]float64 AdditionalInfo() interface{} }
ConverterInfo holds information about converter setup
type RateConverter ¶
type RateConverter struct {
// contains filtered or unexported fields
}
RateConverter holds the currencies conversion rates dictionary
func NewRateConverter ¶
func NewRateConverter( httpClient httpClient, syncSourceURL string, staleRatesThreshold time.Duration, ) *RateConverter
NewRateConverter returns a new RateConverter
func (*RateConverter) GetInfo ¶
func (rc *RateConverter) GetInfo() ConverterInfo
GetInfo returns setup information about the converter
func (*RateConverter) LastUpdated ¶
func (rc *RateConverter) LastUpdated() time.Time
LastUpdated returns time when currencies rates were updated
func (*RateConverter) Rates ¶
func (rc *RateConverter) Rates() Conversions
Rates returns current conversions rates
func (*RateConverter) Run ¶
func (rc *RateConverter) Run() error
type Rates ¶
type Rates struct { DataAsOf time.Time `json:"dataAsOf"` Conversions map[string]map[string]float64 `json:"conversions"` }
Rates holds data as represented on https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json note that `DataAsOfRaw` field is needed when parsing remote JSON as the date format if not standard and requires custom parsing to be properly set as Golang time.Time
func (*Rates) GetRate ¶
GetRate returns the conversion rate between two currencies returns an error in case the conversion rate between the two given currencies is not in the currencies rates map
func (*Rates) UnmarshalJSON ¶
UnmarshalJSON unmarshal raw JSON bytes to Rates object