1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-04 05:08:38 -04:00

Pass DB as a closure instead of a global variable

This is part of an ongoing attempt to restructure the code to make it
more 'testable'.
This commit is contained in:
2017-10-04 08:05:51 -04:00
parent 9abafa50b2
commit 156b9aaf0c
13 changed files with 253 additions and 208 deletions

View File

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
"gopkg.in/gorp.v1"
"time"
)
@ -93,8 +91,8 @@ func GetClosestPriceTx(transaction *gorp.Transaction, security, currency *Securi
}
}
func GetClosestPrice(security, currency *Security, date *time.Time) (*Price, error) {
transaction, err := DB.Begin()
func GetClosestPrice(db *DB, security, currency *Security, date *time.Time) (*Price, error) {
transaction, err := db.Begin()
if err != nil {
return nil, err
}
@ -113,10 +111,3 @@ func GetClosestPrice(security, currency *Security, date *time.Time) (*Price, err
return price, nil
}
func init() {
q, err := finance.GetQuote("BRK-A")
if err == nil {
fmt.Printf("%+v", q)
}
}