package module
Version: v0.0.0-...-2948fd1 Latest Latest

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

Go to latest
Published: Sep 8, 2018 License: MIT Imports: 6 Imported by: 0


Thin wrapper for

A thin wrapper in Go for, 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.


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

$ go get

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


First, let's import the package:

import ""

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

exchange := fixerio.New()

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

if rates, err := exchange.GetRates(); err == nil {

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.


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

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:




Package Fixerio provides a simple interface to the API, a service for currency exchange rates.



View Source
const (
	AUD = "AUD"
	BGN = "BGN"
	BRL = "BRL"
	CAD = "CAD"
	CHF = "CHF"
	CNY = "CNY"
	CZK = "CZK"
	DKK = "DKK"
	EUR = "EUR"
	GBP = "GBP"
	HKD = "HKD"
	HRK = "HRK"
	HUF = "HUF"
	IDR = "IDR"
	ILS = "ILS"
	INR = "INR"
	JPY = "JPY"
	KRW = "KRW"
	MXN = "MXN"
	MYR = "MYR"
	NOK = "NOK"
	NZD = "NZD"
	PHP = "PHP"
	PLN = "PLN"
	RON = "RON"
	RUB = "RUB"
	SEK = "SEK"
	SGD = "SGD"
	THB = "THB"
	USD = "USD"
	ZAR = "ZAR"


This section is empty.


This section is empty.


type Request

type Request struct {
	// contains filtered or unexported fields

Holds the request parameters.

func New

func New() *Request

Initializes fixerio.

func (*Request) APIKey

func (f *Request) APIKey(key string)

func (*Request) Base

func (f *Request) Base(currency string)

Sets base currency.

func (*Request) GetRates

func (f *Request) GetRates() (rates, error)

Retrieve the exchange rates.

func (*Request) GetUrl

func (f *Request) GetUrl() string

Formats the URL correctly for the API Request.

func (*Request) Historical

func (f *Request) Historical(date time.Time)

Specify a date in the past to retrieve historical records.

func (*Request) Secure

func (f *Request) Secure(secure bool)

Make the connection secure or not by setting the secure argument to true or false.

func (*Request) Symbols

func (f *Request) Symbols(currencies ...string)

List of currencies that should be returned.

type Response

type Response struct {
	Base  string `json:"base"`
	Date  string `json:"date"`
	Rates rates  `json:"rates"`

JSON response object.

Jump to

Keyboard shortcuts

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