💱 Currency exchange rates server - Golang "ƓØ"
Swap allows you to retrieve currency exchange rates from various services such as Google, Yahoo, Fixer, CurrencyLayer or 1Forge and optionally cache the results.
curl -X POST \
https://go-swap-server.herokuapp.com/convert \
-H 'Content-Type: application/json' \
-d '{
"amount": 2.5,
"from": "USD",
"to": "AED",
"decimalPoints": 4,
"cacheTime": "120s",
"exchanger": [
{
"name": "yahoo"
},
{
"name": "google"
},
{
"name": "themoneyconverter",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0"
}
]
}'
# Response example
# {
# "to": "AED",
# "from": "USD",
# "exchangerName": "yahoo",
# "exchangeValue": 3.6721,
# "originalAmount": 2.5,
# "convertedAmount": 9.1802,
# "convertedText": "2.5 USD is worth 9.1802 AED",
# "rateDateTime": "2018-09-30T07:45:45Z",
# "rateFromCache": false
# }
# Or using docker
$ docker pull meio/go-swap-server:latest && \
docker run --rm --name go-swap-server -p 5000:5000 -it meio/go-swap-server:latest
$ go get github.com/me-io/go-swap
package main
import (
"fmt"
ex "github.com/me-io/go-swap/pkg/exchanger"
"github.com/me-io/go-swap/pkg/swap"
)
func main() {
SwapTest := swap.NewSwap()
SwapTest.
AddExchanger(ex.NewGoogleApi(nil)).
Build()
euroToUsdRate := SwapTest.Latest("EUR/USD")
fmt.Println(euroToUsdRate.GetRateValue())
}
/GET
/POST
120s Default
Default
4 Default
The documentation for the current branch can be found here.
Exchanger | type | # | $ |
---|---|---|---|
HTML / Regex | :heavy_check_mark: | Free | |
Yahoo | JSON / API | :heavy_check_mark: | Free |
Currency Layer | JSON / API | :heavy_check_mark: | Paid - ApiKey |
Fixer.io | JSON / API | :heavy_check_mark: | Paid - ApiKey |
1forge | API | :heavy_check_mark: | Freemium / Paid - ApiKey |
The Money Converter | HTML / Regex | :heavy_check_mark: | Free |
Open Exchange Rates | API | :heavy_check_mark: | Freemium / Paid - ApiKey |
./cmd/server/public
memory leak
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:
Inspired by florianv/swap
The code is available under the MIT license.