golang rest api example
Gin + Postgres
Graceful shutdown
Config
read from a file and environment variables Middleware
rate limit, authentication: jwtTesting
test real db and mock testLogger
customize and write logs to fileDatabase
implement db queries and transactionRun
app with minimal docker image CI
Github actionInstall go-migrate: https://github.com/golang-migrate/migrate/tree/master/cmd/migrate
Install postgres and create db
make posgres
make createdb
make migrateup
Run directly: go run main.go
Run with docker-compose
make docker_build // build docker with binary file
make docker_run // run docker-compose
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
make test
go get github.com/golang/mock/mockgen@v1.5.0
vi ~/.zshrc
export PATH=$PATH:~/go/bin # Add line
source ~/.zshrc
which mockgen
--> /home/$USER/go/bin/mockgen
make mock