fixerio

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

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

README

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];

Documentation

Overview

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

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL