Coder Social home page Coder Social logo

im-qarch / go-automatic-chainsaw Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 806 KB

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

Home Page: https://github.com/im-Qarch/go-automatic-chainsaw

License: MIT License

Go 92.19% Makefile 1.58% Dockerfile 0.43% Shell 5.80%
docker gin go golang gomock makefile postgres sqlc testify viper

go-automatic-chainsaw's Introduction

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

go-automatic-chainsaw's People

Contributors

im-qarch avatar

Stargazers

 avatar

Watchers

 avatar

go-automatic-chainsaw's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.