Documentation ¶
Overview ¶
Package controllers exposes a controller that connects business rules and models
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheService ¶
type CacheService struct {
Cache *redis.Client
}
CacheService represents the cache connection service
func NewCacheService ¶
func NewCacheService(addr, pw string, db int) *CacheService
NewCacheService returns a new cache service object
type CacheStore ¶
type CacheStore struct { *CacheService Store }
CacheStore wraps any object that satisfies the Store interface with caching capabilities
func (*CacheStore) Credit ¶
func (chs *CacheStore) Credit(wid, amount string) (decimal.Decimal, error)
Credit updates the balance in storage and cache
func (*CacheStore) Debit ¶
func (chs *CacheStore) Debit(wid, amount string) (decimal.Decimal, error)
Debit updates the balance in storage and cache
func (*CacheStore) GetBalance ¶
func (chs *CacheStore) GetBalance(wid string) (decimal.Decimal, error)
GetBalance attempts to fetch a wid's balance from cache, gets it from storage otherwise
type Store ¶
type Store interface { GetBalance(wid string) (decimal.Decimal, error) Credit(wid, amount string) (decimal.Decimal, error) Debit(wid, amount string) (decimal.Decimal, error) }
Store is an interface that implements functions to be used for cache and storage alike
type WalletController ¶
WalletController is a controller for wallet operations
func NewWalletController ¶
func NewWalletController(service *models.DBService) *WalletController
NewWalletController initializes a new wallet controller
func (*WalletController) Credit ¶
func (wc *WalletController) Credit(wid, amount string) (decimal.Decimal, error)
Credit fetches from storage the object identified by wid and credits an amount
func (*WalletController) Debit ¶
func (wc *WalletController) Debit(wid, amount string) (decimal.Decimal, error)
Debit fetches from storage the object identified by wid and debits an amount
func (*WalletController) GetBalance ¶
func (wc *WalletController) GetBalance(wid string) (decimal.Decimal, error)
GetBalance fetches from storage the balance of the object identified by wid and returns it