gopenexchangerates

package module
v0.0.0-...-6a37b95 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2013 License: MIT Imports: 5 Imported by: 2

README

gopenexchangerates

Open Exchange Rates client for Go. Doesn't do much.

Install

go get github.com/jagregory/gopenexchangerates

Usage

import (
  oxr "github.com/jagregory/gopenexchangerates"
)

xr := oxr.New("your-app-id")
err := rx.Populate()
if err != nil {
  // err
}
v, err := rx.Get("AUD") // 1.543

Populate fetches the exchange rates from Open Exchange Rates. Call this method whenever you want to update the cached copy of the rates. Be kind to Open Exchange Rates and don't hammer them.

// update exchange rates every 2 hours
go func() {
  for {
    rx.Populate()
    time.Sleep(2 * time.Hour)
  }
}()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Empty = errors.New("Cache empty, ensure you've successfully called Populate at least once.")

Functions

This section is empty.

Types

type ExchangeRates

type ExchangeRates struct {
	Base string

	Timestamp time.Time
	// contains filtered or unexported fields
}

func New

func New(appid string) *ExchangeRates

Create a new exchange rates cache

func (*ExchangeRates) All

func (r *ExchangeRates) All() (map[string]float64, error)

Get all the exchange rates

func (*ExchangeRates) Get

func (r *ExchangeRates) Get(currency string) (float64, error)

Get the exchange rate for a currency

func (*ExchangeRates) Populate

func (r *ExchangeRates) Populate() error

Populate the rates from Open Exchange Rates

Jump to

Keyboard shortcuts

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