go-currency
go-currency is a currency exchange rate converter service written in Go. By default uses Fixer.io as exchange rate provider.
Online version (heroku)
Heroku - go-currency
Install & Run
This project assumes that you are working in a standard Go workspace, as described in http://golang.org/doc/code.html.
Bash
# Go to your $GOPATH
$ cd $GOPATH
# Download and build
$ go get github.com/floreks/go-currency
# Run it
$ ./bin/go-currency --port <OPTIONAL_PORT>
Docker
Container can be stopped using CTRL+C
.
Building own image
# Go to your $GOPATH
$ cd $GOPATH
# Download and build
$ go get github.com/floreks/go-currency
$ cd $GOPATH/src/github.com/floreks/go-currency
# Build docker image
$ docker build -t go-currency .
# Run our service
$ docker run -p 8080:8080 go-currency
DockerHub image
Check it out on docker hub: go-currency
In order to run it just type in your console:
$ docker run -p 8080:8080 floreks/go-currency
Usage
Let's assume that the application is running on localhost:8080
. Service can produce XML/JSON output based on request header.
XML output
Exchange rates for 200 SEK
curl -H "Accept: application/xml, */*" "http://localhost:8080/convert?amount=200¤cy=SEK"
JSON output
Exchange rates for 200 SEK
curl "http://localhost:8080/convert?amount=200¤cy=SEK"
Offline provider
Additionally if Fixer.io
is offline we can fallback to local provider that uses exchange rates from 31.10.2016
. It supports only 3 base currencies: EUR
, PLN
, USD
.
curl "http://localhost:8080/convert?amount=200¤cy=PLN&provider=local"
Running tests
Go to your project directory and run:
$ go test ./...