Skip to content

Full Back-end system for simple bank app based on GO, boost by [postgres/Kubernetes/gPRC/sqlc/docker/gin/...]

License

Notifications You must be signed in to change notification settings

im-Qarch/go-automatic-chainsaw

Repository files navigation

go-automatic-chainsaw -> bank-app [WIP]

Roadmap

Section I : Working with database [Postgres]

🗒 1. dbdiagram.io Design DB schema and generate SQL code and PDF as a report.



🐳 2. init docker create container/images and run for test

  • postgres:latest hub
  • run database migration in Golang golang-migrate after this [check migrate --version]
    mkdir -p db/migration
    migrate create -ext sql -dir db/migration -seq init_schema  #you will see up/down migration files
    create Makefile in your root (to create/drop db with ease)
    make createdb # you should see db by name bank_db
     # after migrate up to find out migration version and stats
    ls -l db/migration


🗄️ 3. initial type-safe SQL compiler by sqlc

also you can use ORM like GORM but after some research like.1, like.2,... we decide to use sqlc

-   install sqlc
docker pull sqlc/sqlc #then use docker run ...
#or
yay sqlc

then init sqlc and generate sqlc config like here , insure use postgres config

then create all needed schemas files like here and queries files like here based on your db find sample here

then run

make sqlc # after this ./db/sqlc directory should contain generated go files [account/entry/transfer/.../db/model]

then you can write your own custom query like AddAccountBalance or default standard CRUD and enjoy



🧪 4. init Unit test by testify

go get github.com/stretchr/testify #install package
go mod tidy #to update all used packages

then init your main_test.go for all test connection to db

now you can your test by sample for your account CRUD like this.

then run

make test # run all test by coverage

after run you can check success coverage code by highlights


👨‍💻 5. init CI/CD github Actions

  • to init git hub actions fot GO see the doc
  • then you need to setup postgres in your ci config see doc
  • then you need to setup migration in your ci config see doc

final config should look like this


🍸 6. Implement RESTful HTTP API using Gin and Mock DB for testing HTTP API using Gomock

  • after install gin :

    • create api folder and server.go file for base service configuration
    • create main.go main.go file in root to init go for db,server
    • after make server you can use Thunder Client or postman to check and test api
  • after install gomock :

    • check installed is correctly by mockgen -version
    • make Store as interface and make Querier by set emit_interface: true in sqlc
    • create mock folder in db dir and :
      make mock #path project go package / path store (db/sqlc)
      check store.go

⚙️ 7. Extra Configurations

  • 🔰 install viper as a configuration file solution.

    go get github.com/spf13/viper

    then create app.env file to define configs. and config.go file to load configs in app


  • 🔰 install paseto as a Platform-Agnostic Security Tokens. also you can use JWT, but after some research we decide to use paseto

    go get -u github.com/o1egl/paseto

    then create maker file to define base auth-token flow. and paseto_maker file to define paseto configs.

    🟨 Initial auth-middleware to handle user access to apis just by right token


🐳 8. Dockerize app for release and [Build a minimal Golang Docker image with a multistage Dockerfile]

  • first create Dockerfile in root dir then go to docker-hub to find-out golang official image for docker write basic config for build your go app and run :

    docker build -t go-automatic-chainsaw:latest . #tag with name of app and base path

    so let's make it ease with docker-compose

    docker compose up