This service will provide APIs for the frontend to do following things:
- Create and manage bank accounts, which are composed of owner’s name, balance, and currency.
- 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.
- 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.
This project already deployed, you can access Swagger at https://bank.api.umarhadi.dev/swagger.
-
brew install golang-migrate
-
npm install -g dbdocs dbdocs login
-
npm install -g @dbml/cli dbml2sql --version
-
brew install sqlc
-
go install github.com/golang/mock/mockgen@v1.6.0
-
Create the bank-network
make network
-
Start postgres container:
make postgres
-
Create simple_bank database:
make createdb
-
Run db migration up all versions:
make migrateup
-
Run db migration up 1 version:
make migrateup1
-
Run db migration down all versions:
make migratedown
-
Run db migration down 1 version:
make migratedown1
-
Generate DB documentation:
make db_docs
-
Access the DB documentation at this link.
-
Generate schema SQL file with DBML:
make db_schema
-
Generate SQL CRUD with sqlc:
make sqlc
-
Generate DB mock with gomock:
make mock
-
Create a new db migration:
migrate create -ext sql -dir db/migration -seq <migration_name>
-
Run server:
make server
-
Run test:
make test
-
Install nginx ingress controller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml
-
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml
Check out the getting started guide here for installing the Fly CLI. Once you have the CLI installed, you can deploy the app with the following command:
-
Clone the repo:
git clone https://github.com/umarhadi/bank-server.git && cd bank-server
-
Create postgres database:
flyctl postgres create
After that, you will get the database url, save it for later.
-
Set environment variable
-
DB_SOURCE
flyctl secrets set DB_SOURCE="postgres://postgres:db_password@db_host:5432/postgres?sslmode=disable"
Replace
db_password
anddb_host
with the actual password and host from the database url. Don't deletesslmode=disable
part, if you delete it, the app will not be able to connect to the database because connection between the app and the database is not encrypted via fly.io internal network. -
TOKEN_SYMMETRIC_KEY
flyctl secrets set TOKEN_SYMMETRIC_KEY="your_token_symmetric_key"
Replace
your_token_symmetric_key
with your own 32 symmetric key. You can generate it with this tool oropenssl rand -hex 64 | head -c 32
-
Another environment variable
You can change the default value of the environment variable in the
fly.toml
file.
-
-
Deploy the app:
flyctl deploy