exchangerate

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 11 Imported by: 1

README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config config.Config) (core.DataSource, error)

New returns a new weather datasource

Types

type ExchangeRateApi

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

ExchangeRateApi is used as datasource to fetch exchange rates.

func (*ExchangeRateApi) Fetch

func (client *ExchangeRateApi) Fetch() (proto.Message, error)

Fetch calls the specified exchange rate api to get a conversion rate for all requested currency pairs.

Directories

Path Synopsis
lambda module

Jump to

Keyboard shortcuts

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