README: add example for parsing local file

This commit is contained in:
Aaron Ross 2021-01-03 00:21:01 -08:00 committed by Aaron Lindsay
parent 0d93a42626
commit 9136c9bab2
1 changed files with 22 additions and 1 deletions

View File

@ -13,7 +13,7 @@ library.
The main purpose of this project is to provide a library to make it easier to The main purpose of this project is to provide a library to make it easier to
query financial information with OFX from the comfort of Golang, without having query financial information with OFX from the comfort of Golang, without having
to marshal/unmarshal to SGML or XML. The library does *not* intend to abstract to marshal/unmarshal to SGML or XML. The library does _not_ intend to abstract
away all of the details of the OFX specification, which would be difficult to do away all of the details of the OFX specification, which would be difficult to do
well. Instead, it exposes the OFX SGML/XML hierarchy as structs which mostly well. Instead, it exposes the OFX SGML/XML hierarchy as structs which mostly
resemble it. Its primary goal is to enable the creation of other personal resemble it. Its primary goal is to enable the creation of other personal
@ -94,6 +94,27 @@ if stmt, ok := response.Bank[0].(*ofxgo.StatementResponse); ok {
} }
``` ```
Similarly, if you have an OFX file available locally, you can parse it directly:
```go
func main() {
f, err := os.Open("./transactions.qfx")
if err != nil {
fmt.Printf("can't open file: %v\n", err)
return
}
defer f.Close()
resp, err := ofxgo.ParseResponse(f)
if err != nil {
fmt.Printf("can't parse response: %v\n", err)
return
}
// do something with resp (*ofxgo.Response)
}
```
## Requirements ## Requirements
OFXGo requires go >= 1.12 OFXGo requires go >= 1.12