Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wiliamhw/simplebank
Project to practice making Restful API in Golang.
https://github.com/wiliamhw/simplebank
docker docker-compose gin golang golang-crypto golang-jwt golang-migrate golang-viper gomock makefile paseto postgresql sqlc testify-mocking
Last synced: about 22 hours ago
JSON representation
Project to practice making Restful API in Golang.
- Host: GitHub
- URL: https://github.com/wiliamhw/simplebank
- Owner: wiliamhw
- Created: 2022-04-23T06:47:26.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-28T18:02:40.000Z (about 2 years ago)
- Last Synced: 2024-11-28T20:06:32.519Z (about 2 months ago)
- Topics: docker, docker-compose, gin, golang, golang-crypto, golang-jwt, golang-migrate, golang-viper, gomock, makefile, paseto, postgresql, sqlc, testify-mocking
- Language: Go
- Homepage:
- Size: 224 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simplebank
Taken from a Udemy Course named [Backend Master Class (Golang + PostgreSQL + Kubernetes)](https://www.udemy.com/course/backend-master-class-golang-postgresql-kubernetes/?referralCode=DD082CB0A39D22EC43EE).
This project implements all subjects from the course, except AWS, Kubernetes, and gRPC.
I also modified some code on API unit test and application configuration.## Simple bank service
This project 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
### Tools
- [Docker](https://docs.docker.com/engine/)
- [TablePlus](https://tableplus.com/)
- [Golang](https://golang.org/)
- [Migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)```bash
curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/migrate.list
apt-get update
apt-get install -y migrate
```- [DB Docs](https://dbdocs.io/docs)
```bash
npm install -g dbdocs
dbdocs login
```- [DBML CLI](https://www.dbml.org/cli/#installation)
```bash
npm install -g @dbml/cli
dbml2sql --version
```- [Sqlc](https://github.com/kyleconroy/sqlc#installation)
```bash
sudo snap install sqlc
```- [Gomock](https://github.com/golang/mock)
``` bash
go install github.com/golang/mock/mockgen
```### Setup infrastructure
- Start postgres container:
```bash
make postgres
```- Create simple_bank database:
```bash
make createdb
```- Run db migration up all versions:
```bash
make migrateup
```- Run db migration up 1 version:
```bash
make migrateup1
```- Run db migration down all versions:
```bash
make migratedown
```- Run db migration down 1 version:
```bash
make migratedown1
```### Documentation
- Generate DB documentation:
```bash
make db_docs
```- Access the DB documentation at [this address](https://dbdocs.io/wiliamwijaya1985/simple_bank). Password: `secret`
- The Postman API collection and environtment can be exported using JSON files inside [`doc/postman`](doc/postman/) folder.
### How to generate code
- Generate schema SQL file with DBML:
```bash
make db_schema
```- Generate SQL CRUD with sqlc:
```bash
make sqlc
```- Generate DB mock with gomock:
```bash
make mockdb
```- Create a new db migration:
```bash
migrate create -ext sql -dir db/migration -seq
```### How to run
- Run server:
```bash
make server
```- Run test:
```bash
make test
```