gomoney

package module
v0.0.0-...-30e130a Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2019 License: MIT Imports: 7 Imported by: 0

README

Gomoney

A library implemented in golang to convert money into other currencies

Build Statuscodecov

Description

This package contains a simple library which converts a currency amount to another supported currency. The exchange rates used here are published by the official European Central Bank.

For improved performance the exchange rates are cached and refreshed every 2 hours.

Usage

import "github.com/gsingharoy/gomoney"

// generate a new money object
// Note: Check the section below for the supported currencies
m, err := gomoney.NewMoney(100, "USD")

// now convert the money to another currency
// convertedAmount will contain the conversion of 100 USD to CHF
convertedAmount, err := m.Convert("CHF")

The following currencies are supported :

  • EUR : Euro
  • USD : US dollar
  • JPY : Japanese yen
  • BGN : Bulgarian lev
  • CZK : Czech koruna
  • DKK : Danish krone
  • GBP : Pound sterling
  • HUF : Hungarian forint
  • PLN : Polish zloty
  • RON : Romanian leu
  • SEK : Swedish krona
  • CHF : Swiss franc
  • NOK : Norwegian krone
  • HRK : Croatian kuna
  • RUB : Russian rouble
  • TRY : Turkish lira
  • AUD : Australian dollar
  • BRL : Brazilian real
  • CAD : Canadian dollar
  • CNY : Chinese yuan renminbi
  • HKD : Hong Kong dollar
  • IDR : Indonesian rupiah
  • ILS : Israeli shekel
  • INR : Indian rupee
  • KRW : South Korean won
  • MXN : Mexican peso
  • MYR : Malaysian ringgit
  • NZD : New Zealand dollar
  • PHP : Philippine peso
  • SGD : Singapore dollar
  • THB : Thai baht
  • ZAR : South African rand

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMoneyObject = errors.New("missing exchange rates")
View Source
var ErrUnsupportedCurrency = errors.New("unsupported currency")

Functions

This section is empty.

Types

type Money

type Money struct {
	// Amount which needs to be converted
	Amount float64
	// Base currency of the amount.
	BaseCurrency string
	// contains filtered or unexported fields
}

Represents the basic Money unit. Contains 3 main fields, viz., Amount, BaseCurrency and CurrConversion

func NewMoney

func NewMoney(amount float64, baseCurrency string) (*Money, error)

Returns a new Money instance amount: [float64] Amount of the currency you want the money struct to be initialted with baseCurrency: [string] 3 char value of string. Accepted values are (case insensitive)

[]string{
    "USD",
    "JPY",
    "BGN",
    "CZK",
    "DKK",
    "GBP",
    "HUF",
    "PLN",
    "RON",
    "SEK",
    "CHF",
    "NOK",
    "HRK",
    "RUB",
    "TRY",
    "AUD",
    "BRL",
    "CAD",
    "CNY",
    "HKD",
    "IDR",
    "ILS",
    "INR",
    "KRW",
    "MXN",
    "MYR",
    "NZD",
    "PHP",
    "SGD",
    "THB",
    "ZAR",
}

func (*Money) Convert

func (m *Money) Convert(currency string) (*Money, error)

Converts the money into the currency inputted currency: [string] 3 char value of string. Accepted values are (case insensitive)

[]string{
    "USD",
    "JPY",
    "BGN",
    "CZK",
    "DKK",
    "GBP",
    "HUF",
    "PLN",
    "RON",
    "SEK",
    "CHF",
    "NOK",
    "HRK",
    "RUB",
    "TRY",
    "AUD",
    "BRL",
    "CAD",
    "CNY",
    "HKD",
    "IDR",
    "ILS",
    "INR",
    "KRW",
    "MXN",
    "MYR",
    "NZD",
    "PHP",
    "SGD",
    "THB",
    "ZAR",
}

Jump to

Keyboard shortcuts

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