A golang toolkit to interface with a ledger journal file
This project aims to satisfy my usage patterns with ledger. For example, there are many parts of the journal format that I do not use (like check numbers). I don't plan on supporting these functions, but if you wish to implement them, feel free to submit a pull request.
This project is in very heavy development!
The ledger package wraps go types around specific ledger-cli command line interfaces.
The main object is journal, which is constructed in the following way:
To construct one, you need to first construct a type that satisfies the journalReader interface. We provide a basic file reader in this package. Then you can create a journal object:
fileJournal := NewFileReader("/path/to/ledger/journal.dat")
journal := NewJournal(fileJournal)The journal type has the following functions on it:
This returns a slice of account balances, not including budget accounts.
balances := j.Balances()
// []Balance{Balance{Name:"Assets:Checking:Test Account",Value:"$123.45"}}This returns a slice of budgets in the journal, which are defined as an account which has a Budget:Assets prefix.
budgets := j.Budgets()
// []Budget{Budget{Name:"Budget:Assets:Rent",Value:"$123.45"}}This returns a slice of transactions for an account.
trans := j.AccountTransactions("Assets:Checking:Test Account")
// []AccountTransaction{AccountTransaction{...}}This adds a transaction to the ledger file
t := j.AddTransaction(Transaction{...})This deletes a transaction from the ledger file, specified by the transaction id
err := j.DeleteTransaction("some-id")