frankfurter

package
v0.0.0-...-a220720 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Currency

type Currency string

type ExchangeRates

type ExchangeRates struct {
	Date   YMD
	Amount float32
	Base   Currency
	Rates  Rates
}

type ExchangeRatesService

type ExchangeRatesService struct {
	HttpClient *http.Client
	URL        string
}

func (ExchangeRatesService) At

func (s ExchangeRatesService) At(ctx context.Context, date YMD, currencies ...Currency) (*ExchangeRates, error)

At fetches the rates at the given date

If one or more currencies are passed, only those will be fetched. If none are passed, _all_ currencies will be fetched.

If the returned version is not the one requested, it fails. While Frankfurter returns the closest rate, Concourse explicitly states that the resource must fail if the requested version is not available.

func (ExchangeRatesService) Latest

func (s ExchangeRatesService) Latest(ctx context.Context, currencies ...Currency) (*ExchangeRates, error)

Latest fetches the latest rates

func (ExchangeRatesService) Since

func (s ExchangeRatesService) Since(ctx context.Context, date YMD, currencies ...Currency) (*History, error)

Since fetches the rates between the given date and now

type History

type History struct {
	Amount float32
	Base   Currency
	Start  YMD     `json:"start_date"`
	End    YMD     `json:"end_date"`
	Rates  RatesAt `json:"rates"`
}

type Rates

type Rates map[Currency]float32

type RatesAt

type RatesAt map[YMD]Rates

func (*RatesAt) UnmarshalJSON

func (ra *RatesAt) UnmarshalJSON(raw []byte) error

UnmarshalJSON provides custom unmarshaling as we cannot naiively unmarshal a map with time.Time keys.

type YMD

type YMD time.Time

YMD specializes time.Time encoded as YYYY-MM-DD The time zone is hard-coded to Europe/Berlin, which is the same as Frankfurt. The time is hard-coded to 16:00 because this is what the ECB specifies:

"The reference rates are usually updated at around 16:00 CET every working day, except on TARGET closing days."

from https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html

func NewYMD

func NewYMD(s string) (YMD, error)

func (YMD) Before

func (d YMD) Before(u YMD) bool

func (YMD) Equal

func (d YMD) Equal(other YMD) bool

func (YMD) IsZero

func (d YMD) IsZero() bool

func (YMD) MarshalJSON

func (d YMD) MarshalJSON() ([]byte, error)

func (YMD) String

func (d YMD) String() string

func (*YMD) UnmarshalJSON

func (d *YMD) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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