currency

package
v0.46.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package currency provides currency conversion interfaces and implementations.

Index

Constants

View Source
const ISOCurrencyCAD = "CAD"

ISOCurrencyCAD is the ISO-4217 currency code for CAD.

View Source
const ISOCurrencyCHF = "CHF"

ISOCurrencyCHF is the ISO-4217 currency code for CHF.

View Source
const ISOCurrencyCNY = "CNY"

ISOCurrencyCNY is the ISO-4217 currency code for CNY.

View Source
const ISOCurrencyEUR = "EUR"

ISOCurrencyEUR is the ISO-4217 currency code for EUR.

View Source
const ISOCurrencyGBP = "GBP"

ISOCurrencyGBP is the ISO-4217 currency code for GBP.

View Source
const ISOCurrencyJPY = "JPY"

ISOCurrencyJPY is the ISO-4217 currency code for JPY.

View Source
const ISOCurrencyUSD = "USD"

ISOCurrencyUSD is the ISO-4217 currency code for USD.

View Source
const IntervalNever = time.Duration(0)

Variables

View Source
var ErrNoSnapshot = errors.New("currency snapshot not found")
View Source
var ErrUnavailable = errors.New("currency conversion unavailable")

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 WithInterval(interval time.Duration) fwaOption

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

func NewDummyConverter(factor float64) Converter

NewDummyConverter creates a new dummy currency converter.

type Downloader added in v0.46.1

type Downloader interface {
	Download(ctx context.Context) (*Snapshot, error)
}

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 Runner added in v0.46.1

type Runner interface {
	Run(ctx context.Context)
}

Runner starts background converter refresh work.

type Snapshot added in v0.46.1

type Snapshot struct {
	CreatedAt time.Time                     `json:"created_at"`
	Rates     map[string]map[string]float64 `json:"rates"`
}

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

type SnapshotStore interface {
	Latest() (*Snapshot, error)
	Append(snapshot *Snapshot) error
}

func NewFileStore added in v0.46.1

func NewFileStore(directory string) SnapshotStore

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL