Documentation ¶
Overview ¶
Package rates 0.2.2 This package helps to manage exchange rates from any provider
Example 1: Get all exchange rates for the ECB Provider
package main import ( "fmt" "github.com/openprovider/rates" "github.com/openprovider/rates/providers" ) func main() { service := rates.New( // any collection of providers which implement rates.Provider interface providers.NewECBProvider(new(rates.Options)), ) rates, errors := service.FetchLast() if len(errors) != 0 { fmt.Println(errors) } fmt.Println("European Central Bank exchange rates for today") for index, rate := range rates { fmt.Printf("%d. %s - %v\r\n", index+1, rate.Currency, rate.Value) } }
Example 2: Get exchange rates for EUR, USD, CHF, HKD
package main import ( "fmt" "github.com/openprovider/rates" "github.com/openprovider/rates/providers" ) func main() { registry := rates.Registry{ // any collection of providers which implement rates.Provider interface providers.NewECBProvider( &rates.Options{ Currencies: []string{ providers.EUR, providers.USD, providers.CHF, providers.HKD, }, }, ), } rates, errors := registry.FetchLast() if len(errors) != 0 { fmt.Println(errors) } fmt.Println("European Central Bank exchange rates for today") for index, rate := range rates { fmt.Printf("%d. %s - %v\r\n", index+1, rate.Currency, rate.Value) } }
Exchange Rates Provider
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // API key/token Token string // List of the currencies which need to get from the provider // If it is empty, should get all of existing currencies from the provider Currencies []string // Flexible settings list Settings map[string]interface{} }
Options is some specific things for the specific provider It should configure the provider to manage currencies
type Provider ¶
type Provider interface { Name() string FetchLast() (rates []Rate, errors []error) FetchHistory() (rates []Rate, errors []error) }
Provider holds methods for providers which implement this interface
type Rate ¶
type Rate struct { ID uint64 `json:"id,omitempty"` Date string `json:"date"` Currency string `json:"currency"` Time time.Time `json:"-"` Base currency.Unit `json:"-"` Unit currency.Unit `json:"-"` Value interface{} `json:"value"` }
Rate represent date and currency exchange rates
Click to show internal directories.
Click to hide internal directories.