currency

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopConverter

type NoopConverter struct{}

NoopConverter assumes all currencies are the same and returns the input unchanged.

func NewNoopConverter

func NewNoopConverter() *NoopConverter

NewNoopConverter returns a new NoopConverter instance.

func (*NoopConverter) Convert

func (c *NoopConverter) Convert(ctx context.Context, amountCents int64, fromCurrency, toCurrency string) (int64, error)

Convert returns amountCents unchanged.

type StaticConverter

type StaticConverter struct {
	// contains filtered or unexported fields
}

StaticConverter holds a static rate table for currency conversion. Rates are expressed in basis points: rate["USD"]["BRL"] = 50000 means 1 USD = 5.0000 BRL. The conversion formula is: (amountCents * rate) / 10000.

func NewStaticConverter

func NewStaticConverter(rates map[string]map[string]int64) *StaticConverter

NewStaticConverter returns a new StaticConverter with the given rates.

func (*StaticConverter) Convert

func (c *StaticConverter) Convert(ctx context.Context, amountCents int64, fromCurrency, toCurrency string) (int64, error)

Convert converts amountCents from fromCurrency to toCurrency using the static rate table. It uses integer arithmetic with a fixed precision of 4 decimal places (10000 divisor).

Jump to

Keyboard shortcuts

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