Documentation
¶
Index ¶
- type Bank
- type BankClient
- func (client *BankClient) Deposit(amount int, idempotencyKey string) (string, error)
- func (client *BankClient) GetBalance() (int, error)
- func (client *BankClient) GetName() (string, error)
- func (client *BankClient) IsServiceRunning() bool
- func (client *BankClient) Withdraw(amount int, idempotencyKey string) (string, error)
- type BankingService
- type InsufficientFundsError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bank ¶
type Bank struct {
// contains filtered or unexported fields
}
Bank represents an institution that offers basic financial accounts to customers. For the sake of simplicity in this demo, a given bank only has a single customer. This source file contains the business logic for managing the account and persisting the balance across sessions. The service.go file contains logic for exposing methods for account management over a network through a basic HTTP API. Implementation note: At present, idempotency keys are only retained for the lifetime of the service; they are not persisted during the current session and therefore values used then are not available for checking in the next session.
func NewBank ¶
NewBank returns a Bank instance for the named account. The balance for that account will be the same as in the previous session, or if there was no previous session, it will be zero (in which case you might call the Deposit method to provide initial funding).
func (*Bank) Deposit ¶
Deposit adds the specified amount to the balance. The idempotency key is used to identify duplicate requests. This returns the transaction ID if successful or will return an error if the amount is invalid (zero or negative).
func (*Bank) GetBalance ¶
GetBalance returns the current account balance
func (*Bank) GetDataPath ¶
GetDataPath returns the path of the file where account data is persisted
type BankClient ¶
type BankClient struct {
// contains filtered or unexported fields
}
BankClient allows a caller to invoke operations (such as Withdraw and Deposit) provided by a banking service available via a network.
func NewBankClient ¶
func NewBankClient(host string, port int) *BankClient
NewBankClient creates a BankClient and returns a pointer to it.
func (*BankClient) Deposit ¶
func (client *BankClient) Deposit(amount int, idempotencyKey string) (string, error)
Deposit calls the banking service, requesting that it adds the specified amount to the balance. The idempotency key is used to identify duplicate requests. This returns the transaction ID if successful or an error if it was not.
func (*BankClient) GetBalance ¶
func (client *BankClient) GetBalance() (int, error)
GetBalance returns the current account balance
func (*BankClient) GetName ¶
func (client *BankClient) GetName() (string, error)
GetName returns the name of the bank that the client will access
func (*BankClient) IsServiceRunning ¶
func (client *BankClient) IsServiceRunning() bool
IsServiceRunning returns true if the service is available, false otherwise
func (*BankClient) Withdraw ¶
func (client *BankClient) Withdraw(amount int, idempotencyKey string) (string, error)
Withdraw removes the specified amount from the balance. The idempotency key is used to identify duplicate requests. This returns a transaction ID if successful or will return an error if the amount is invalid (either negative or greater than the current balance).
type BankingService ¶
type BankingService struct {
// contains filtered or unexported fields
}
BankingService represents account operations that a specific bank allows one to invoke over a network connection.
func NewBankingService ¶
func NewBankingService(bank *Bank, port int) *BankingService
NewBankingService creates a new BankingService and returns a pointer to it.
func (*BankingService) Shutdown ¶
func (svc *BankingService) Shutdown() error
Shutdown stops the BankingService, preventing it from handling client reqests
func (*BankingService) Start ¶
func (svc *BankingService) Start() error
Start starts the BankingService, allowing it to handle client reqests
type InsufficientFundsError ¶
type InsufficientFundsError struct {
// contains filtered or unexported fields
}
InsufficientFundsError occurs when an account lacks the funds to successfully perform the requested operation.
func (InsufficientFundsError) Error ¶
func (e InsufficientFundsError) Error() string