Documentation ¶
Overview ¶
Package bank was made for the Master Go course at appliedgo.com.
Index ¶
- func Balance(a *Account) int
- func Deposit(a *Account, m int) (int, error)
- func History(a *Account) func() (amt, bal int, more bool)
- func ListAccounts() string
- func Load() error
- func Name(a *Account) string
- func Save() (err error)
- func Transfer(a, b *Account, m int) (int, int, error)
- func Withdraw(a *Account, m int) (int, error)
- type Account
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func History ¶
History returns a closure that returns one account transaction at a time. On each call, the closure returns the amount of the transaction, the resulting balance, and a boolean that is true as long as there are more history elements to read. The closure returns the history items from oldest to newest. The closure panics if it is called again after its third return value has turned "false".
func ListAccounts ¶
func ListAccounts() string
ListAccounts returns a formatted string that lists each account and its current balance.
Types ¶
type Account ¶
func GetAccount ¶
GetAccount receives a name and returns the account of that name, if it exists. GetAccount panics if the bank has no accounts.
func NewAccount ¶
NewAccount creates a new account with a name. Initial balance is 0. The new account is added to the bank's map of accounts.
Example ¶
a := NewAccount("Test") fmt.Println(Name(a))
Output: Test