Help us shape the future of Go! Take the 2026 Go Developer Survey

currency

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package currency provides a currency conversion interface and implementation.

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.

Variables

This section is empty.

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

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.

func NewFWAConverter added in v0.4.0

func NewFWAConverter(initialBases []string) (Converter, error)

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.

func (*FWAConverter) Convert added in v0.4.0

func (c *FWAConverter) Convert(isoBaseCurrency, isoQuoteCurrency string, amount float64) (float64, error)

Convert implements Converter.Convert.

Jump to

Keyboard shortcuts

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