HomeDashboard Exchange Rate DataSource
Fetches exchange rates for specified currencies.
Config
Config have to contain URL of an exchange rate API and a list of currencie pairs an exchange rate should be fetched.
More details about loading config at https://github.com/tommzn/go-config
Config example
exchangerate:
url: "https://api.frankfurter.app/latest"
date_format: "2006-01-02"
conversions:
- from: "EUR"
to: "USD"
- from: "USD"
to: "EUR"
Usage
After creating a new datasource, you can fetch specified exchange rates. If anything works well Fetch will return a exchange rates struct or otherwise an error.
import (
exchangerate "github.com/tommzn/hdb-datasource-exchangerate"
events "github.com/tommzn/hdb-events-go"
)
datasource, err := exchangerate.New(config)
if err != nil {
panic(err)
}
weatherData, err := datasource.Fetch()
if err != nil {
panic(err)
}
fmt.Printf("Exchange Rates: %d\n", len(weatherData.(events.ExchangeRates).Rates))
Links