Documentation
¶
Index ¶
- Constants
- Variables
- func NewCurrencyModule() kernel.ModuleFactory
- func RegisterProvider(name string, option ProviderFactory)
- type Body
- type Content
- type ECBProviderHistoricalExchangeResponse
- type ExchangeResponse
- type HistoricalBody
- type Module
- type OpenExchangeRatesApiResponse
- type Provider
- type ProviderFactory
- type ProviderSettings
- type ProvidersConfig
- type Rate
- type Sender
- type Service
- type Settings
- type UpdaterService
Constants ¶
const ( Eur = "EUR" Usd = "USD" )
const ( ECBProviderName = "ecb" ExchangeRateECBUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" HistoricalExchangeRateECBUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml" )
const ( OpenExchangeRatesApiProviderName = "openexchangeratesapi" OpenExchangeRatesUrl = "https://openexchangerates.org/api/" )
const ( ExchangeRateRefresh = 8 * time.Hour ExchangeRateDateKey = "currency_exchange_last_refresh" HistoricalExchangeRateDateKey = "currency_exchange_historical_last_refresh" )
const RatesAmount = 200
RatesAmount We expect to have around 200 currencies in total. It's okay to exceed the limit, but it's nice to avoid unnecessary reallocations.
Variables ¶
var Currencies = map[string]string{ Eur: "€", Usd: "$", }
Functions ¶
func NewCurrencyModule ¶
func NewCurrencyModule() kernel.ModuleFactory
NewCurrencyModule returns a kernel module factory for the currency module. The module will start a background process that periodically updates exchange rates from configured providers. By default, it will update historical exchange rates for the last 30 days. If you need to create a new table with all the data, it is recommended to copy data from an existing table.
func RegisterProvider ¶ added in v0.49.2
func RegisterProvider(name string, option ProviderFactory)
RegisterProvider registers a new currency provider with the given name and factory. If a provider with the same name already exists, it will be overwritten. Providers should be registered before currency module is initialized (e.g. in init function).
Types ¶
type ECBProviderHistoricalExchangeResponse ¶ added in v0.49.2
type ECBProviderHistoricalExchangeResponse struct {
Subject string `xml:"subject"`
Sender Sender `xml:"Sender"`
Body HistoricalBody `xml:"Cube"`
}
type ExchangeResponse ¶
type HistoricalBody ¶
type HistoricalBody struct {
Content []Content `xml:"Cube"`
}
type Module ¶
type Module struct {
kernel.EssentialBackgroundModule
kernel.ServiceStage
// contains filtered or unexported fields
}
type OpenExchangeRatesApiResponse ¶ added in v0.49.2
type Provider ¶ added in v0.49.2
type Provider interface {
Name() string
GetPriority() int
FetchLatestRates(ctx context.Context) ([]Rate, error)
FetchHistoricalRates(ctx context.Context, dates []time.Time) (map[time.Time][]Rate, error)
}
func NewECBProviderWithInterfaces ¶ added in v0.49.2
func NewOpenExchangeRatesApiProviderWithInterfaces ¶ added in v0.49.2
type ProviderFactory ¶ added in v0.49.2
type ProviderSettings ¶ added in v0.49.2
type ProvidersConfig ¶ added in v0.49.2
type ProvidersConfig map[string]ProviderSettings
type Service ¶
type Service interface {
HasCurrency(ctx context.Context, currency string) (bool, error)
HasCurrencyAtDate(ctx context.Context, currency string, date time.Time) (bool, error)
ToEur(ctx context.Context, value float64, fromCurrency string) (float64, error)
ToEurAtDate(ctx context.Context, value float64, fromCurrency string, date time.Time) (float64, error)
ToUsd(ctx context.Context, value float64, fromCurrency string) (float64, error)
ToUsdAtDate(ctx context.Context, value float64, fromCurrency string, date time.Time) (float64, error)
ToCurrency(ctx context.Context, toCurrency string, value float64, fromCurrency string) (float64, error)
ToCurrencyAtDate(ctx context.Context, toCurrency string, value float64, fromCurrency string, date time.Time) (float64, error)
}
type UpdaterService ¶
type UpdaterService interface {
EnsureRecentExchangeRates(ctx context.Context) error
EnsureHistoricalExchangeRates(ctx context.Context) error
}