This repository contains a project I have learn about design, develop and deploy a complete backend system using Go, PostgreSQL and Docker.
Clone this repository:
git clone https://github.com/scul0405/simple_bank.git
cd simple_bank
Run this command:
docker compose up
On Linux/Mac use make
to execute Makefile command (if you use Windows, you can use mingw32-make
instead or rename mingw32-make
to make
):
Install and run PostgreSQL docker container:
make postgres
Create database:
make createdb
Migrate database:
make migrateup
Run server:
make server
Now server is started on http://localhost:3000/ for HTTP server and http://localhost:8080/ for gRPC server. You can use Evans to send request to gRPC server by use this command:
make evans
POST /v1/create_user
: Create a new userPOST /v1/login_user
: Login user and get access token & refresh token
You can change to Gin server by change line:39, 40
in main.go
to runGinServer(config, store)
POST /users
: Create a new userPOST /users/login
: Login user and get access token & refresh tokenPOST /tokens/renew_access
: Return new access tokenPOST /accounts
: Create a new accountGET /accounts/:id
: Get an account with account's IDPOST /transfers
: Transfer money between 2 accounts
Run testing for all packages with random data
make test
-
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 migrateuplast
-
Run db migration down all versions:
make migratedown
-
Run db migration down 1 version:
make migratedownlast
-
Generate DB documentation:
make db_docs
-
Access the DB documentation at this address. Password:
secret
-
Run server:
make server
-
Go to http://localhost:3000/swagger to view API documentation
-
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>