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 pgstart
to initialize the docker database container. - Run
make createdb
to create the database. - Connect to the DB with TablePlus or any other DB client.
- Run
make migrateup
to run the migrations.
- Run
- For subsequent connections:
- Run
make postgresstart
to 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 server
in 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/query
folder.- SQLC looks at the
sqlc.yaml
file in the root directory to configure and generate the code. - To add new/update SQL queries:
- Write the queries in the
db/query
folder. - To generate the SQLC code, run
make sqlc
in the root directory of the project. - The generated code is placed in the
db/sqlc
directory.models.go
contains the structs for the tables in the database.db.go
contains 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.go
file in thedb/sqlc
directory 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 mockdb
in the root directory of the project. - To generate the mock services, run
make mockservice
in the root directory of the project.
- To generate the mock db, run