account

package
v0.0.0-...-877dc42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(as Service, logger kitlog.Logger) http.Handler

MakeHandler returns a handler for the account service.

Types

type Account

type Account struct {
	ID       string               `json:"id"`
	Balances map[Currency]float64 `json:"balances,omitempty"`
}

Account represents id holding multiple currencies

func New

func New() *Account

New creates account with id

func (*Account) AppendBalance

func (a *Account) AppendBalance(currency Currency, amount float64)

AppendBalance adds or removes from account balance for given currency

func (*Account) BalanceFor

func (a *Account) BalanceFor(currency Currency) float64

BalanceFor returns amount for given currency

func (*Account) HasFunds

func (a *Account) HasFunds(currency Currency, amount float64) bool

HasFunds checks if the account has enough amount for given currency

func (*Account) SetBalance

func (a *Account) SetBalance(currency Currency, amount float64)

SetBalance hard reset balance for given currency

type Currency

type Currency string

Currency represents the key for global currency

type Repository

type Repository interface {
	Store(*Account) error
	Find(id string) (*Account, error)
	FindAll() []*Account
}

Repository provides access a account store.

type Service

type Service interface {
	// CreateAccount creates new account with generated ID
	CreateAccount() (*Account, error)

	// GetAccount returns account by ID
	GetAccount(string) (*Account, error)

	// Accounts lists all accounts
	Accounts() []*Account

	// SetBalanceForAccount hard reset balance for account for given currency
	SetBalanceForAccount(*Account, Currency, float64) (*Account, error)
}

Service is the interface that provides account methods.

func NewService

func NewService(accounts Repository) Service

NewService creates account service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL