mirror of
https://github.com/aclindsa/ofxgo.git
synced 2025-07-03 20:38:39 -04:00
cmd/ofx: check for nil Currency fields in transactions
This commit is contained in:
@ -77,7 +77,7 @@ func bankTransactions() {
|
|||||||
|
|
||||||
func printTransaction(defCurrency ofxgo.CurrSymbol, tran *ofxgo.Transaction) {
|
func printTransaction(defCurrency ofxgo.CurrSymbol, tran *ofxgo.Transaction) {
|
||||||
currency := defCurrency
|
currency := defCurrency
|
||||||
if ok, _ := tran.Currency.Valid(); ok {
|
if tran.Currency != nil {
|
||||||
currency = tran.Currency.CurSym
|
currency = tran.Currency.CurSym
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func ccTransactions() {
|
|||||||
fmt.Println("Transactions:")
|
fmt.Println("Transactions:")
|
||||||
for _, tran := range stmt.BankTranList.Transactions {
|
for _, tran := range stmt.BankTranList.Transactions {
|
||||||
currency := stmt.CurDef
|
currency := stmt.CurDef
|
||||||
if ok, _ := tran.Currency.Valid(); ok {
|
if tran.Currency != nil {
|
||||||
currency = tran.Currency.CurSym
|
currency = tran.Currency.CurSym
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,11 +362,7 @@ type Currency struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Valid returns whether the Currency is valid according to the OFX spec
|
// Valid returns whether the Currency is valid according to the OFX spec
|
||||||
func (c *Currency) Valid() (bool, error) {
|
func (c Currency) Valid() (bool, error) {
|
||||||
if c == nil {
|
|
||||||
return false, errors.New("Currency is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.CurRate.IsInt() && c.CurRate.Num().Int64() == 0 {
|
if c.CurRate.IsInt() && c.CurRate.Num().Int64() == 0 {
|
||||||
return false, errors.New("CurRate may not be zero")
|
return false, errors.New("CurRate may not be zero")
|
||||||
} else if ok, err := c.CurSym.Valid(); !ok {
|
} else if ok, err := c.CurSym.Valid(); !ok {
|
||||||
|
Reference in New Issue
Block a user