currency

package
v0.26.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Eur = "EUR"
	Usd = "USD"
)
View Source
const (
	ExchangeRateRefresh           = 8 * time.Hour
	ExchangeRateUrl               = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
	HistoricalExchangeRateUrl     = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"
	ExchangeRateDateKey           = "currency_exchange_last_refresh"
	HistoricalExchangeRateDateKey = "currency_exchange_historical_last_refresh"
)
View Source
const YMDLayout = "2006-01-02"

Variables

View Source
var Currencies = map[string]string{
	Eur: "€",
	Usd: "$",
}

Functions

func NewCurrencyModule

func NewCurrencyModule() kernel.ModuleFactory

Types

type Body

type Body struct {
	Content Content `xml:"Cube"`
}

type Content

type Content struct {
	Time  string `xml:"time,attr"`
	Rates []Rate `xml:"Cube"`
}

func (Content) GetTime

func (c Content) GetTime() (time.Time, error)

type Currency

type Currency string

type ExchangeResponse

type ExchangeResponse struct {
	Subject string `xml:"subject"`
	Sender  Sender `xml:"Sender"`
	Body    Body   `xml:"Cube"`
}

type HistoricalBody

type HistoricalBody struct {
	Content []Content `xml:"Cube"`
}

type HistoricalExchangeResponse

type HistoricalExchangeResponse struct {
	Subject string         `xml:"subject"`
	Sender  Sender         `xml:"Sender"`
	Body    HistoricalBody `xml:"Cube"`
}

type Module

type Module struct {
	kernel.EssentialBackgroundModule
	kernel.ServiceStage
	// contains filtered or unexported fields
}

func (Module) IsHealthy added in v0.23.0

func (module Module) IsHealthy(ctx context.Context) (bool, error)

func (Module) Run

func (module Module) Run(ctx context.Context) error

type Rate

type Rate struct {
	Currency string  `xml:"currency,attr"`
	Rate     float64 `xml:"rate,attr"`
}

type Sender

type Sender struct {
	Name string `xml:"name"`
}

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)
}

func New

func New(ctx context.Context, config cfg.Config, logger log.Logger) (Service, error)

func NewWithInterfaces

func NewWithInterfaces(store kvstore.KvStore[float64], clock clock.Clock) Service

type UpdaterService

type UpdaterService interface {
	EnsureRecentExchangeRates(ctx context.Context) error
	EnsureHistoricalExchangeRates(ctx context.Context) error
}

func NewUpdater

func NewUpdater(ctx context.Context, config cfg.Config, logger log.Logger) (UpdaterService, error)

func NewUpdaterWithInterfaces

func NewUpdaterWithInterfaces(logger log.Logger, store kvstore.KvStore[float64], httpClient http.Client, clock clock.Clock) UpdaterService

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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