This is a simple bank application that allows users to create an account, deposit, withdraw, and transfer money between accounts.
- Golang/Gin
- PostgreSQL
- Docker
- Docker Compose
- Makefile
- Sqlc
- Gomock
- Testify
- Golang-migrate
-
The database is running on port 5432 in the docker container.
- If connecting to the DB for the first time:
- Run
make pgstartto initialize the docker database container. - Run
make createdbto create the database. - Connect to the DB with TablePlus or any other DB client.
- Run
make migrateupto run the migrations.
- Run
- For subsequent connections:
- Run
make postgresstartto start the database container. - To stop the database container, run
make pgstop.
- Run
- If connecting to the DB for the first time:
-
Gin server is running on port 8080. Start the server by running
make serverin the root directory of the project. Make sure the database is running before starting the server. -
SQLC is used to generate idiomatic Go code for working with the database based on the pre-defined SQL queries we've written in the
db/queryfolder.- SQLC looks at the
sqlc.yamlfile in the root directory to configure and generate the code. - To add new/update SQL queries:
- Write the queries in the
db/queryfolder. - To generate the SQLC code, run
make sqlcin the root directory of the project. - The generated code is placed in the
db/sqlcdirectory.models.gocontains the structs for the tables in the database.db.gocontains the Queries struct for using with a sql.DB object or with a sql.Tx object for transactions.- The Go code ends with
.sql.go.
- Make sure to create the corresponding
<table>_test.gofile in thedb/sqlcdirectory to test the generated code.
- Write the queries in the
- SQLC looks at the
-
Gomock / Mockgen is used to generate a mock db and mock services for testing the 2 layers.
- To generate the mock db, run
make mockdbin the root directory of the project. - To generate the mock services, run
make mockservicein the root directory of the project.
- To generate the mock db, run