currencies

package
v0.0.0-...-97a8816 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateConverter

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

RateConverter holds the currencies conversion rates dictionnary

func NewRateConverter

func NewRateConverter(
	httpClient httpClient,
	syncSourceURL string,
	fetchingInterval time.Duration,
) *RateConverter

NewRateConverter returns a new RateConverter

func NewRateConverterWithNotifier

func NewRateConverterWithNotifier(
	httpClient httpClient,
	syncSourceURL string,
	fetchingInterval time.Duration,
	updateNotifier chan<- int,
) *RateConverter

NewRateConverterWithNotifier returns a new RateConverter it allow to pass an update chan in which the number of ticks will be passed after each tick allowing clients to listen on updates Do not use this method

func (*RateConverter) LastUpdated

func (rc *RateConverter) LastUpdated() time.Time

LastUpdated returns time when currencies rates were updated

func (*RateConverter) Rates

func (rc *RateConverter) Rates() *Rates

Rates returns current rates

func (*RateConverter) StopPeriodicFetching

func (rc *RateConverter) StopPeriodicFetching()

StopPeriodicFetching stops the periodic fetching while keeping the latest currencies rates map

func (*RateConverter) Update

func (rc *RateConverter) Update() error

Update updates the internal currencies rates from remote sources

type Rates

type Rates struct {
	DataAsOf    time.Time                     `json:"dataAsOf"`
	Conversions map[string]map[string]float64 `json:"conversions"`
}

Rates holds data as represented on http://currency.prebid.org/latest.json note that `DataAsOfRaw` field is needed when parsing remote JSON as the date format if not standard and requires custom parsing to be properly set as Golang time.Time

func NewRates

func NewRates(dataAsOf time.Time, conversions map[string]map[string]float64) *Rates

NewRates creates a new Rates object holding currencies rates

func (*Rates) GetRate

func (r *Rates) GetRate(from string, to string) (float64, error)

GetRate returns the conversion rate between two currencies returns an error in case the conversion rate between the two given currencies is not in the currencies rates map

func (*Rates) UnmarshalJSON

func (r *Rates) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal raw JSON bytes to Rates object

Jump to

Keyboard shortcuts

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