atmsystem

package module
v0.0.0-...-6be6b1c Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2015 License: MIT Imports: 6 Imported by: 0

README

atmsystem

Remote Invocation Implementation of A Simple ATM System

Submitted Files

account.go - structure for account
bank.go - rpc interface
client.go - structure and methods for client
server.go - structure and methods for server
storage.go - interface for storage

server/main.go - executable for server
server/ldbs.go - contains implementation for the storage interface

client/main.go - executable for client

Building

To install Go follow the guide here

One can obtain the source using the go get command to download and install
go get github.com/jacoblusk/atmsystem

Or seperately one can download the source and use solong as their $GOPATH is set one can use go get to install the dependinces and run using go build
go build github.com/jacoblusk/atmsystem/server
go build github.com/jacoblusk/atmsystem/client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID      int `bson:"id"`
	Balance int `bson:"balance"`
}

func (*Account) MarshalBSON

func (a *Account) MarshalBSON() ([]byte, error)

func (*Account) UnmarshalBSON

func (a *Account) UnmarshalBSON(b []byte) error

type Bank

type Bank struct {
	// contains filtered or unexported fields
}

Here we use a mutex for Withdraw and Deposit as there is a possible race condition between checking if the account exists and depositing. This assignment doesn't have us deleting user acctions, but for scalability reasons it is used.

func NewBank

func NewBank(s Storage) *Bank

func (*Bank) Deposit

func (b *Bank) Deposit(t, reply *Transaction) error

func (*Bank) Inquiry

func (b *Bank) Inquiry(id int, r *Transaction) error

func (*Bank) Withdraw

func (b *Bank) Withdraw(t, reply *Transaction) error

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(addr string, timeout time.Duration) (*Client, error)

func (*Client) Deposit

func (c *Client) Deposit(id, amount int) (int, error)

func (*Client) Inquiry

func (c *Client) Inquiry(id int) (int, error)

func (*Client) Withdraw

func (c *Client) Withdraw(id, amount int) (int, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

The server contains an instance of bank, and the net.Listener interface. As of now, this server isn't stoppable; but could be by implementing a stoppable listener.

func NewServer

func NewServer(storage Storage) *Server

func (*Server) Start

func (s *Server) Start(laddr string) (err error)

type Storage

type Storage interface {
	PutAccount(account *Account) error
	GetAccount(id int) (*Account, error)
	Exists(id int) (bool, error)
}

Here we define the Storage interface which is used by the server's package main to implement server specific storage.

type Transaction

type Transaction struct {
	ID, Amount int
}

This is the object that is passed as both a request and a reply, it could be abstracted further to have a seperate reply object for each RPC method, but that wasn't needed for this assignment.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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