go_swap

package module
v0.0.0-...-b8d825d Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: MIT Imports: 0 Imported by: 0

README

Currency Exchange Server - Golang

Build Status Go Report Card Coverage Status GoDoc GitHub release

Blog URL COMMIT SIZE-LAYERS Pulls

Swap allows you to retrieve currency exchange rates from various services such as Google, Yahoo, Fixer, CurrencyLayer or 1Forge and optionally cache the results.

Playground

Swagger UI
/GET Examples for single exchanger:
/POST Examples for single or multi exchanger:
  • CURL examples:
    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
     # }  
    
  • Run in SwaggerUI
  • Run in Postman

QuickStart

Deploy
# 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

Programmatically

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

Features

  • Convert with Single exchange source /GET
  • Convert with Multi exchange sources with fallback mechanism /POST
    • Google
    • Yahoo
    • CurrencyLayer
    • Fixer.io
    • themoneyconverter.com
    • openexchangerates.org
    • 1forge.com
  • Rate Caching - 120s Default
    • Memory - Default
    • Redis
  • Rate decimal points rounding 4 Default
  • Swagger UI
  • Clear API Request and Response
  • Docker image, Binary release and Heroku Demo
  • Clear documentation and 90%+ code coverage
  • Unit tested on live and mock data

Screens

Documentation

The documentation for the current branch can be found here.

Services

Exchanger type # $
Google HTML / Regex Free
Yahoo JSON / API Free
Currency Layer JSON / API Paid - ApiKey
Fixer.io JSON / API Paid - ApiKey
1forge API Freemium / Paid - ApiKey
The Money Converter HTML / Regex Free
Open Exchange Rates API Freemium / Paid - ApiKey

Uptime Monitor

Deploy

TODO LIST

  • error structure for empty json or regex not matched
  • convert panic to api json error
  • increase tests
  • verbose logging
  • godoc
  • static bundle public folder ./cmd/server/public
  • v 1.0.0 release ( docker / binary github / homebrew mac )
  • support historical rates if possible
  • benchmark & performance optimization memory leak
  • contributors list

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:

Credits

Inspired by florianv/swap

License

The code is available under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VERSION = "0.0.1"

VERSION is the app-global version string, which should be substituted with a real value during build.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
pkg
test

Jump to

Keyboard shortcuts

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