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:
13
prices.go
13
prices.go
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user