Git Product home page Git Product logo

simple_bank's Introduction

SIMPLE BANK

This repository contains a project I have learn about design, develop and deploy a complete backend system using Go, PostgreSQL and Docker.

Setup local development

Install tools

Quick start

Clone this repository:

git clone https://github.com/scul0405/simple_bank.git
cd simple_bank

Using with docker compose

Run this command:

docker compose up

Using by default

On Linux/Mac use make to execute Makefile command (if you use Windows, you can use mingw32-make instead or rename mingw32-make to make):

Install and run PostgreSQL docker container:

    make postgres

Create database:

    make createdb

Migrate database:

    make migrateup

Run server:

    make server

Now server is started on http://localhost:3000/ for HTTP server and http://localhost:8080/ for gRPC server. You can use Evans to send request to gRPC server by use this command:

    make evans

API endpoints

With gateway server

  • POST /v1/create_user: Create a new user
  • POST /v1/login_user: Login user and get access token & refresh token

With Gin server

You can change to Gin server by change line:39, 40 in main.go to runGinServer(config, store)

  • POST /users: Create a new user
  • POST /users/login: Login user and get access token & refresh token
  • POST /tokens/renew_access: Return new access token
  • POST /accounts: Create a new account
  • GET /accounts/:id: Get an account with account's ID
  • POST /transfers: Transfer money between 2 accounts

Testing

Run testing for all packages with random data

make test

Setup infrastructure

  • Start postgres container:

    make postgres
  • Create simple_bank database:

    make createdb
  • Run db migration up all versions:

    make migrateup
  • Run db migration up 1 version:

    make migrateuplast
  • Run db migration down all versions:

    make migratedown
  • Run db migration down 1 version:

    make migratedownlast

Documentation

Database

  • Generate DB documentation:

    make db_docs
  • Access the DB documentation at this address. Password: secret

Swagger (API Documentation)

How to generate code

  • Generate schema SQL file with DBML:

    make db_schema
  • Generate SQL CRUD with sqlc:

    make sqlc
  • Generate DB mock with gomock:

    make mock
  • Create a new db migration:

    migrate create -ext sql -dir db/migration -seq <migration_name>

simple_bank's People

Contributors

scul0405 avatar

Stargazers

An Nguyên avatar Queensalats avatar  avatar

Watchers

Kostas Georgiou avatar  avatar

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.