oxr

package
v0.0.0-...-d9a9959 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCurrency

func ConvertCurrency(from, to string, amount float64, date time.Time) (float64, error)

Convert an amount between two currencies. Uses historical exchange rates for the given timestamp.

func Setup

func Setup(options *Options)

Prepares for Open Exchange Rates API calls. Includes setting up the exchange rate cache. Expects environment variables such as

Types

type Cache

type Cache interface {
	Add(string, Rates) error
	Get(string) (*Rates, error)
}

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRU cache is an in-memory implementation of the OXR cache interface using an LRU as the caching method.

func NewLRUCache

func NewLRUCache(size int) (*LRUCache, error)

Create a new LRU cache.

func (*LRUCache) Add

func (cache *LRUCache) Add(key string, rates Rates) error

Implements Cache.Add

func (*LRUCache) Get

func (cache *LRUCache) Get(key string) (*Rates, error)

Implements Cache.Get

type MongoCache

type MongoCache struct {
	// contains filtered or unexported fields
}

Mongo Cache is a MongoDB implementation of the OXR cache. It uses an existing mgo session to connect to MongoDB rather than setting up it's own.

func NewMongoCache

func NewMongoCache(session *mgo.Session, db string, collection string) *MongoCache

Create a new Mongo cache with the given target database and collection

func (*MongoCache) Add

func (cache *MongoCache) Add(key string, rates Rates) error

Implements Cache.Add

func (*MongoCache) Get

func (cache *MongoCache) Get(key string) (*Rates, error)

Implements Cache.Get

type NotFoundError

type NotFoundError struct{}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Options

type Options struct {
	Token string
	Cache Cache
}

Setup options for Open Exchange Rates

type Rates

type Rates struct {
	ID        string             `json:"id" bson:"_id"`
	License   string             `json:"license" bson:"license"`
	Timestamp int                `json:"timestamp" bson:"timestamp"`
	Base      string             `json:"base" bson:"base"`
	Rates     map[string]float64 `json:"rates" bson:"rates"`
}

func Historical

func Historical(date string) (*Rates, error)

Returns historical rates for the given date string, formatted as "yyyy-mm-dd"

Jump to

Keyboard shortcuts

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