Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAndAddCurrency(input []string, check string) []string
- func ContainsBaseCurrency(baseCurrencies []string, currency string) bool
- func ContainsBaseCurrencyIndex(baseCurrencies []string, currency string) (bool, string)
- func ContainsSeparator(input string) (bool, string)
- func ConvertCurrency(amount float64, from, to string) (float64, error)
- func FetchFixerCurrencyData() error
- func FetchYahooCurrencyData(currencyPairs []string) error
- func GetProvider() string
- func IsCryptocurrency(currency string) bool
- func IsDefaultCryptocurrency(currency string) bool
- func IsDefaultCurrency(currency string) bool
- func IsFiatCurrency(currency string) bool
- func MakecurrencyPairs(supportedCurrencies string) string
- func QueryYahooCurrencyValues(currencies string) error
- func SeedCurrencyData(fiatCurrencies string) error
- func SetProvider(yahooEnabled bool)
- func SwapProvider()
- type FixerResponse
- type Rate
- type YahooJSONResponse
- type YahooJSONResponseInfo
Constants ¶
const ( // DefaultCurrencies has the default minimum of FIAT values DefaultCurrencies = "USD,AUD,EUR,CNY" // DefaultCryptoCurrencies has the default minimum of crytpocurrency values DefaultCryptoCurrencies = "BTC,LTC,ETH,DOGE,DASH,XRP,XMR" )
Variables ¶
var ( CurrencyStore map[string]Rate CurrencyStoreFixer map[string]float64 BaseCurrencies string CryptoCurrencies string ErrCurrencyDataNotFetched = errors.New("yahoo currency data has not been fetched yet") ErrCurrencyNotFound = errors.New("unable to find specified currency") ErrQueryingYahoo = errors.New("unable to query Yahoo currency values") ErrQueryingYahooZeroCount = errors.New("yahoo returned zero currency data") YahooEnabled = false )
Variables for package which includes base error strings & exportable queries
Functions ¶
func CheckAndAddCurrency ¶
CheckAndAddCurrency checks the string you passed with the input string array, if not already added, checks to see if it is part of the default currency list and returns the appended string.
func ContainsBaseCurrency ¶
ContainsBaseCurrency checks the currency against the baseCurrencies and returns a bool
func ContainsBaseCurrencyIndex ¶
ContainsBaseCurrencyIndex checks the currency against the baseCurrencies and returns a bool and its corresponding basecurrency.
func ContainsSeparator ¶
ContainsSeparator checks to see if the string passed contains "-" or "_" separated strings and returns what the separators were.
func ConvertCurrency ¶
ConvertCurrency for example converts $1 USD to the equivalent Japanese Yen or vice versa.
func FetchFixerCurrencyData ¶
func FetchFixerCurrencyData() error
FetchFixerCurrencyData seeds the variable C
func FetchYahooCurrencyData ¶
FetchYahooCurrencyData seeds the variable CurrencyStore; this is a map[string]Rate
func GetProvider ¶
func GetProvider() string
GetProvider returns the currency exchange service used by the currency converter
func IsCryptocurrency ¶
IsCryptocurrency checks if the currency passed is an enabled CRYPTO currency.
func IsDefaultCryptocurrency ¶
IsDefaultCryptocurrency checks if the currency passed in matches the default CRYPTO currency
func IsDefaultCurrency ¶
IsDefaultCurrency checks if the currency passed in matches the default FIAT currency
func IsFiatCurrency ¶
IsFiatCurrency checks if the currency passed is an enabled FIAT currency
func MakecurrencyPairs ¶
MakecurrencyPairs takes all supported currency and turns them into pairs.
func QueryYahooCurrencyValues ¶
QueryYahooCurrencyValues takes in desired currencies, creates pairs then uses FetchYahooCurrencyData to seed CurrencyStore
func SeedCurrencyData ¶
SeedCurrencyData takes the desired FIAT currency string, if not defined the function will assign it the default values. The function will query yahoo for the currency values and will seed currency data.
func SetProvider ¶
func SetProvider(yahooEnabled bool)
SetProvider sets the currency exchange service used by the currency converter
func SwapProvider ¶
func SwapProvider()
SwapProvider swaps the currency exchange service used by the curency converter
Types ¶
type FixerResponse ¶
type FixerResponse struct { Base string `json:"base"` Date string `json:"date"` Rates map[string]float64 `json:"rates"` }
FixerResponse contains the data fields for the Fixer API response
type Rate ¶
type Rate struct { ID string `json:"id"` Name string `json:"Name"` Rate float64 `json:",string"` Date string `json:"Date"` Time string `json:"Time"` Ask float64 `json:",string"` Bid float64 `json:",string"` }
Rate holds the current exchange rates for the currency pair.
type YahooJSONResponse ¶
type YahooJSONResponse struct { Query struct { YahooJSONResponseInfo Results struct { Rate []Rate `json:"rate"` } } }
YahooJSONResponse holds Yahoo API responses