Code Monkey home page Code Monkey logo

go-web-api's Introduction

Go web api

  • Gin + Postgres
  • Graceful shutdown
  • Config read from a file and environment variables
  • Middleware rate limit, authentication: jwt
  • Testing test real db and mock test
  • Logger customize and write logs to file
  • Database implement db queries and transaction
  • Run app with minimal docker image
  • CI Github action

1. Install

 make posgres
 make createdb
 make migrateup

2. Run

  • Run directly: go run main.go

  • Run with docker-compose

    make docker_build  // build docker with binary file
    make docker_run    // run docker-compose

3. Test

   curl -d '{"owner": "cathy", "balance": 150, "currency": "EUR"}' -H "Content-Type: application/json" -X POST http://localhost:8000/api/v1/account/add
  • Update config in file app/config/config.yaml

  • Mock test: make mock_test

  • Unit test: make test

4. Other

  • How use mock generate code:
      go get github.com/golang/mock/[email protected]
    
    • Add go/bin folder to $PATH environment variable: edit PATH in ~/.zshrc or ~/.bashrc
    vi ~/.zshrc  
    export PATH=$PATH:~/go/bin # Add line
    source ~/.zshrc
    which mockgen
    --> /home/$USER/go/bin/mockgen
    
    • Gen mock code: make mock

References

  1. simplebank
  2. gin-admin

go-web-api's People

Contributors

belito3 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.