Documentation
¶
Overview ¶
Package currency provides currency conversion interfaces and implementations.
Index ¶
- Constants
- Variables
- func DoConversion(converter Converter, baseCurrency any, quoteCurrency string, baseValue any) (any, error)
- func WithDestination(directory string) fwaOption
- func WithDownloader(downloader Downloader) fwaOption
- func WithInterval(interval time.Duration) fwaOption
- func WithStore(store SnapshotStore) fwaOption
- type Converter
- type Downloader
- type FWAConverter
- type ManagedConverter
- type Runner
- type Snapshot
- type SnapshotStatus
- type SnapshotStore
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.
const IntervalNever = time.Duration(0)
Variables ¶
var ErrNoSnapshot = errors.New("currency snapshot not found")
ErrUnavailable indicates that conversion data is currently unavailable.
Functions ¶
func DoConversion ¶
func DoConversion( converter Converter, baseCurrency any, quoteCurrency string, baseValue any, ) (any, error)
DoConversion is a helper, that can be used in column implementations to quickly convert a value stored in other columns
func WithDestination ¶ added in v0.46.1
func WithDestination(directory string) fwaOption
func WithDownloader ¶ added in v0.46.1
func WithDownloader(downloader Downloader) fwaOption
func WithInterval ¶ added in v0.46.1
func WithStore ¶ added in v0.46.1
func WithStore(store SnapshotStore) fwaOption
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.
type Downloader ¶ added in v0.46.1
func NewAPIDownloader ¶ added in v0.46.1
func NewAPIDownloader() Downloader
type FWAConverter ¶ added in v0.4.0
type FWAConverter struct {
// contains filtered or unexported fields
}
func (*FWAConverter) Convert ¶ added in v0.4.0
func (c *FWAConverter) Convert(isoBaseCurrency, isoQuoteCurrency string, amount float64) (float64, error)
Convert implements Converter.Convert.
func (*FWAConverter) HasSnapshot ¶ added in v0.46.1
func (c *FWAConverter) HasSnapshot() bool
HasSnapshot reports whether a snapshot is currently loaded in memory.
func (*FWAConverter) Run ¶ added in v0.46.1
func (c *FWAConverter) Run(ctx context.Context)
Run starts the background refresh loop.
type ManagedConverter ¶ added in v0.46.1
type ManagedConverter interface {
Converter
Runner
SnapshotStatus
}
ManagedConverter combines synchronous conversion with background refresh lifecycle.
func NewFWAConverter ¶ added in v0.4.0
func NewFWAConverter(initialBases []string, options ...fwaOption) (ManagedConverter, error)
type SnapshotStatus ¶ added in v0.46.1
type SnapshotStatus interface {
HasSnapshot() bool
}
SnapshotStatus reports whether a usable snapshot is currently loaded.
type SnapshotStore ¶ added in v0.46.1
func NewFileStore ¶ added in v0.46.1
func NewFileStore(directory string) SnapshotStore