fixerio

package module
v0.0.0-...-05ccf84 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 7 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.String())
exchange.Symbols(fixerio.USD.String(), fixerio.AUD.String())
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.String()])
}

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.String(), fixerio.GBP.String())

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.String()];

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Currencies = []string{}/* 168 elements not displayed */

Functions

This section is empty.

Types

type ClientResponse

type ClientResponse struct {
	Date  time.Time
	Base  string
	Rates rates
}

ClientResponse Response object returned by the service.

type Currency

type Currency string
const (
	AED Currency = "AED"
	AFN Currency = "AFN"
	ALL Currency = "ALL"
	AMD Currency = "AMD"
	ANG Currency = "ANG"
	AOA Currency = "AOA"
	ARS Currency = "ARS"
	AUD Currency = "AUD"
	AWG Currency = "AWG"
	AZN Currency = "AZN"
	BAM Currency = "BAM"
	BBD Currency = "BBD"
	BDT Currency = "BDT"
	BGN Currency = "BGN"
	BHD Currency = "BHD"
	BIF Currency = "BIF"
	BMD Currency = "BMD"
	BND Currency = "BND"
	BOB Currency = "BOB"
	BRL Currency = "BRL"
	BSD Currency = "BSD"
	BTC Currency = "BTC"
	BTN Currency = "BTN"
	BWP Currency = "BWP"
	BYN Currency = "BYN"
	BYR Currency = "BYR"
	BZD Currency = "BZD"
	CAD Currency = "CAD"
	CDF Currency = "CDF"
	CHF Currency = "CHF"
	CLF Currency = "CLF"
	CLP Currency = "CLP"
	CNY Currency = "CNY"
	COP Currency = "COP"
	CRC Currency = "CRC"
	CUC Currency = "CUC"
	CUP Currency = "CUP"
	CVE Currency = "CVE"
	CZK Currency = "CZK"
	DJF Currency = "DJF"
	DKK Currency = "DKK"
	DOP Currency = "DOP"
	DZD Currency = "DZD"
	EGP Currency = "EGP"
	ERN Currency = "ERN"
	ETB Currency = "ETB"
	EUR Currency = "EUR"
	FJD Currency = "FJD"
	FKP Currency = "FKP"
	GBP Currency = "GBP"
	GEL Currency = "GEL"
	GGP Currency = "GGP"
	GHS Currency = "GHS"
	GIP Currency = "GIP"
	GMD Currency = "GMD"
	GNF Currency = "GNF"
	GTQ Currency = "GTQ"
	GYD Currency = "GYD"
	HKD Currency = "HKD"
	HNL Currency = "HNL"
	HRK Currency = "HRK"
	HTG Currency = "HTG"
	HUF Currency = "HUF"
	IDR Currency = "IDR"
	ILS Currency = "ILS"
	IMP Currency = "IMP"
	INR Currency = "INR"
	IQD Currency = "IQD"
	IRR Currency = "IRR"
	ISK Currency = "ISK"
	JEP Currency = "JEP"
	JMD Currency = "JMD"
	JOD Currency = "JOD"
	JPY Currency = "JPY"
	KES Currency = "KES"
	KGS Currency = "KGS"
	KHR Currency = "KHR"
	KMF Currency = "KMF"
	KPW Currency = "KPW"
	KRW Currency = "KRW"
	KWD Currency = "KWD"
	KYD Currency = "KYD"
	KZT Currency = "KZT"
	LAK Currency = "LAK"
	LBP Currency = "LBP"
	LKR Currency = "LKR"
	LRD Currency = "LRD"
	LSL Currency = "LSL"
	LTL Currency = "LTL"
	LVL Currency = "LVL"
	LYD Currency = "LYD"
	MAD Currency = "MAD"
	MDL Currency = "MDL"
	MGA Currency = "MGA"
	MKD Currency = "MKD"
	MMK Currency = "MMK"
	MNT Currency = "MNT"
	MOP Currency = "MOP"
	MRO Currency = "MRO"
	MUR Currency = "MUR"
	MVR Currency = "MVR"
	MWK Currency = "MWK"
	MXN Currency = "MXN"
	MYR Currency = "MYR"
	MZN Currency = "MZN"
	NAD Currency = "NAD"
	NGN Currency = "NGN"
	NIO Currency = "NIO"
	NOK Currency = "NOK"
	NPR Currency = "NPR"
	NZD Currency = "NZD"
	OMR Currency = "OMR"
	PAB Currency = "PAB"
	PEN Currency = "PEN"
	PGK Currency = "PGK"
	PHP Currency = "PHP"
	PKR Currency = "PKR"
	PLN Currency = "PLN"
	PYG Currency = "PYG"
	QAR Currency = "QAR"
	RON Currency = "RON"
	RSD Currency = "RSD"
	RUB Currency = "RUB"
	RWF Currency = "RWF"
	SAR Currency = "SAR"
	SBD Currency = "SBD"
	SCR Currency = "SCR"
	SDG Currency = "SDG"
	SEK Currency = "SEK"
	SGD Currency = "SGD"
	SHP Currency = "SHP"
	SLL Currency = "SLL"
	SOS Currency = "SOS"
	SRD Currency = "SRD"
	STD Currency = "STD"
	SVC Currency = "SVC"
	SYP Currency = "SYP"
	SZL Currency = "SZL"
	THB Currency = "THB"
	TJS Currency = "TJS"
	TMT Currency = "TMT"
	TND Currency = "TND"
	TOP Currency = "TOP"
	TRY Currency = "TRY"
	TTD Currency = "TTD"
	TWD Currency = "TWD"
	TZS Currency = "TZS"
	UAH Currency = "UAH"
	UGX Currency = "UGX"
	USD Currency = "USD"
	UYU Currency = "UYU"
	UZS Currency = "UZS"
	VEF Currency = "VEF"
	VND Currency = "VND"
	VUV Currency = "VUV"
	WST Currency = "WST"
	XAF Currency = "XAF"
	XAG Currency = "XAG"
	XAU Currency = "XAU"
	XCD Currency = "XCD"
	XDR Currency = "XDR"
	XOF Currency = "XOF"
	XPF Currency = "XPF"
	YER Currency = "YER"
	ZAR Currency = "ZAR"
	ZMK Currency = "ZMK"
	ZMW Currency = "ZMW"
	ZWL Currency = "ZWL"
)

func (Currency) String

func (t Currency) String() string

type Request

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

Request Holds the request parameters.

func New

func New() *Request

New Initializes fixerio.

func (*Request) AccessKey

func (f *Request) AccessKey(accessKey string)

AccessKey Sets access key.

func (*Request) Base

func (f *Request) Base(currency string)

Sets base currency.

func (*Request) Client

func (f *Request) Client(httpClient *http.Client)

func (*Request) GetRates

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

GetRates Retrieve the exchange rates.

func (*Request) GetURL

func (f *Request) GetURL() string

GetURL Formats the URL correctly for the API Request.

func (*Request) Historical

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

Historical Specify a date in the past to retrieve historical records.

func (*Request) Secure

func (f *Request) Secure(secure bool)

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

func (*Request) Symbols

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

Symbols List of currencies that should be returned.

type Response

type Response struct {
	Success   bool     `json:"success"`
	Timestamp int      `json:"timestamp"`
	Base      string   `json:"base"`
	Date      string   `json:"date"`
	Rates     rates    `json:"rates"`
	Error     apiError `json:"error"`
}

Response JSON response object.

Jump to

Keyboard shortcuts

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