Skip to content

JessyWts/go_simplebank

Repository files navigation

Simple bank service

The service that we’re going to build is a simple bank. It will provide APIs for the frontend to do following things:

  1. Create and manage bank accounts, which are composed of owner’s name, balance, and currency.
  2. Record all balance changes to each of the account. So every time some money is added to or subtracted from the account, an account entry record will be created.
  3. Perform a money transfer between 2 accounts. This should happen within a transaction, so that either both accounts’ balance are updated successfully or none of them are.

Setup local development

Install tools

Setup infrastructure

  • Create the bank-network

    make network
  • Start postgres container:

    make postgres
    • Start redis container:
    make redis
  • Create simple_bank database:

    make createdb
  • Run db migration up all versions:

    make migrate_up
  • Run db migration up last change version:

    make migrate_up_last
  • Run db migration down all versions:

    make migrate_down
  • Run db migration down last change version:

    make migrate_down_last
    • Reset DB to initial state:
    make migrate_down
    make migrate_up

Documentation

  • Generate DB documentation:

    make db_docs
  • Access the DB documentation at this address. Password: secret

How to generate code

  • Generate schema SQL file with DBML:

    make db_schema
  • Generate SQL CRUD with sqlc:

    make sqlc
  • Generate DB mock with gomock:

    make mock
  • Generate a new db migration up and down files:

    make new_migration name=add_role_to_users
  • Generate proto config file and swagger interface:

    make proto

How to run

  • Run server:

    make server
  • Run test:

    make test

Test gRPC server

Start evans cli interface

make evans

List packages

show package

Select a package

package pb

Show services in the package

show service

Connect to service

service SimpleBank

Use the RPC

call CreateUser

Deploy to kubernetes cluster

  • Install nginx ingress controller:

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml
  • Install cert-manager:

    kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published