项目作者: belito3

项目描述 :
golang rest api example
高级语言: Go
项目地址: git://github.com/belito3/go-web-api.git
创建时间: 2020-10-06T10:27:06Z
项目社区:https://github.com/belito3/go-web-api

开源协议:

下载


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

2. Run

  • Run directly: go run main.go

  • Run with docker-compose

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

    3. Test

    1. 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:
    1. go get github.com/golang/mock/mockgen@v1.5.0
    • Add go/bin folder to $PATH environment variable: edit PATH in ~/.zshrc or ~/.bashrc
      1. vi ~/.zshrc
      2. export PATH=$PATH:~/go/bin # Add line
      3. source ~/.zshrc
      4. which mockgen
      5. --> /home/$USER/go/bin/mockgen
    • Gen mock code: make mock

References

  1. simplebank
  2. gin-admin