Documentation
¶
Overview ¶
Package currency provides a currency conversion interface and implementation.
Index ¶
Constants ¶
const ISOCurrencyCAD = "CAD"
ISOCurrencyCAD is the ISO-4217 currency code for CAD.
const ISOCurrencyCHF = "CHF"
ISOCurrencyCHF is the ISO-4217 currency code for CHF.
const ISOCurrencyCNY = "CNY"
ISOCurrencyCNY is the ISO-4217 currency code for CNY.
const ISOCurrencyEUR = "EUR"
ISOCurrencyEUR is the ISO-4217 currency code for EUR.
const ISOCurrencyGBP = "GBP"
ISOCurrencyGBP is the ISO-4217 currency code for GBP.
const ISOCurrencyJPY = "JPY"
ISOCurrencyJPY is the ISO-4217 currency code for JPY.
const ISOCurrencyUSD = "USD"
ISOCurrencyUSD is the ISO-4217 currency code for USD.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Converter ¶
type Converter interface {
Convert(isoBaseCurrency string, isoQuoteCurrency string, amount float64) (float64, error)
}
Converter is an interface that converts currency amounts between different ISO currencies.
func NewDummyConverter ¶
NewDummyConverter creates a new dummy currency converter.
func NewFWAConverter ¶ added in v0.4.0
NewFWAConverter creates a new converter backed by FWAConverter. The constructor synchronously fetches all provided base currencies and blocks until they are downloaded and cached. A background refresher updates all cached bases every hour.
type FWAConverter ¶ added in v0.4.0
type FWAConverter struct {
// contains filtered or unexported fields
}
FWAConverter implements Converter using the fawazahmed0/exchange-api dataset. Available here:https://github.com/fawazahmed0/exchange-api. It maintains an in-memory cache of base-currency rate tables, fetched initially for a provided set of currencies, then refreshed hourly in the background. On-demand, when a conversion is requested for a base currency not yet cached, the converter will fetch and cache that base table before serving the request.