coins

package module
v0.0.0-...-1bf65b7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 2 Imported by: 0

README

Coins

Go Report Card

Generic Wallet service with a RESTful API

Dependencies
  1. Posgresql RDBMS is used as a persistent storage, tables structure and test data can be found in coins.sql
Run
usage: coinsscv [OPTION]...

available commands:
    --addr           set server listen address (default ":8088")
    
Enviroment variables:
	PORT = "8088"
	DSN  = "user=postgres dbname=postgres sslmode=disable"
	
Docker

Requires Docker 17.06 or later for multi-stage build.

git clone https://github.com/darksawa/coins/
cd ./coins
docker-compose up
Test
curl localhost:8089/api/v1/accounts/
# => {
         "accounts":
         [
             {
                 "id": "bob123",
                 "balance": "91.12",
                 "currency": "USD"
             },
             {
                 "id": "alice456",
                 "balance": "8.89",
                 "currency": "USD"
             }
         ]
     }
API

Please read api.md

Install

Install the web server:

go install github.com/darksawa/coins/cmd/coinssvc
Test

Run tests:

go test ./...
Package

Check out godoc reference

GoDoc

Contribution

Please read CONTRIBUTING.md

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotEnoughFunds is used when user does not have enough funds for transfer to another account
	ErrNotEnoughFunds = errors.New("not enough funds")
	// ErrMixedCurrencies is used when user tries to transfer funds to account with different currency
	ErrMixedCurrencies = errors.New("cannot process account with the different currencies")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID       AccountID
	Balance  decimal.Decimal
	Currency Currency
}

Account is a domain model for user account

func (*Account) Transfer

func (a *Account) Transfer(to *Account, amount decimal.Decimal) (*Payment, error)

Transfer transfers certain amount to another account

type AccountID

type AccountID string

AccountID - unique user accounts identifier

type AccountRepository

type AccountRepository interface {
	Update(Transaction, *Account) error
	FindAll() ([]*Account, error)
	FindForUpdate(Transaction, AccountID) (*Account, error)
}

AccountRepository provides accounts store

type Currency

type Currency string

Currency describes account's currency

type Payment

type Payment struct {
	Account   *Account
	ToAccount *Account
	Amount    decimal.Decimal
}

Payment is a domain model for payments

func NewPayment

func NewPayment(from *Account, to *Account, amount decimal.Decimal) *Payment

NewPayment creates a new payment between two accounts

type PaymentDirection

type PaymentDirection int

PaymentDirection describes payment direction between accounts

const (
	Inbound PaymentDirection = iota
	Outbound
)

Valid payment directions

func (PaymentDirection) String

func (p PaymentDirection) String() string

Valid handling of payment directions

type PaymentRepository

type PaymentRepository interface {
	Insert(Transaction, *Payment) error
	FindAll() ([]*Payment, error)
}

PaymentRepository provides payments store

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
}

Transaction is a transaction

type TxStarter

type TxStarter interface {
	Begin() (Transaction, error)
}

TxStarter provides transaction opener

Directories

Path Synopsis
Package account provides the use-case of manipulating with user's account.
Package account provides the use-case of manipulating with user's account.
Package accountfinder provides the use-case of searching for user's accounts.
Package accountfinder provides the use-case of searching for user's accounts.
cmd
Package inmem provides in-memory repository, used for testing purposes Package inmem provides in-memory repository, used for testing purposes Package inmem provides in-memory repository, used for testing purposes
Package inmem provides in-memory repository, used for testing purposes Package inmem provides in-memory repository, used for testing purposes Package inmem provides in-memory repository, used for testing purposes
Package paymentfinder provides the use-case of searching for user's payments.
Package paymentfinder provides the use-case of searching for user's payments.
Package postgres provides PostgreSQL repository Package postgres provides PostgreSQL repository
Package postgres provides PostgreSQL repository Package postgres provides PostgreSQL repository

Jump to

Keyboard shortcuts

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