Skip to content

fadion/gofixerio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thin wrapper for Fixer.io

A thin wrapper in Go for Fixer.io, a service for foreign exchange rates and currency conversion. It provides a few methods to easily construct the url, makes the api call and gives back the response.

Installation

As for any other package, you can use go get:

$ go get github.com/fadion/gofixerio

For better package management however, I'd recommend glide or the still in alpha dep.

Usage

First, let's import the package:

import "github.com/fadion/gofixerio"

Let's see an exhaustive example with all the parameters:

exchange := fixerio.New()

exchange.Base(fixerio.EUR)
exchange.Symbols(fixerio.USD, fixerio.AUD)
exchange.Secure(true)
exchange.Historical(time.Date(2016, time.December, 15, 0, 0, 0, 0, time.UTC))

if rates, err := exchange.GetRates(); err == nil {
    fmt.Println(rates[fixerio.USD])
}

Every parameter can be omitted as the package provides some sensible defaults. The base currency is EUR, makes a secure connection by default and returns all the supported currencies.

Response

The response is a simple map[string]float32 with currencies as keys and ratios as values. For a request like the following:

exchange := fixerio.New()
exchange.Symbols(fixerio.USD, fixerio.GBP)

rates, _ := exchange.GetRates()
fmt.Println(rates)

the response will be the map:

map[USD:1.1188 GBP:0.87093]

which you can access with the keys as strings or using the currency constants:

rates["USD"];
rates[fixerio.GBP];