Go-gin-wrapper is wrapper of gin-gonic/gin web framework plus reverse proxy.
React by ES6 is used on part of front-end. But it's quite outdated.
This project has started since 2016 to study Golang and code is quite messy.
Now it's under refactoring
.
- refactoring code by The Second Edition of "Refactoring"
- refactoring code by codebeat.co
- change architecture like Clean Architecture
- make UI adaptable like WEB to CUI
- fix session functionality
- remove any dependencies from hiromaily/golibs
- use sqlboiler as ORM
- remove MongoDB
- replace log to zap logger
- add zap logger
- add graceful shutdown
- refactoring jwt package
- fix main_test
- unittest by table driven test
- clean up variable, func name
- clean up comments
- catch up with latest gin
- update front-end
- Golang 1.15+
- Docker compose
- MySQL 5.7
- Redis
- direnv for MacOS user
Example is here on Heroku.
OAuth2
authentication with Google/Facebook is available.
JWT(Json Web Token)
is used for authentication.
See configuration [api.auth]
in toml file.
APIs documentation by Swagger
See ./configs/settings.default.toml
As needed, secret information can be encrypted.(using AES encryption)
- MySQL
- Redis whose used as session store
# 1. clone repository
$ git clone https://github.com/hiromaily/go-gin-wrapper.git
# 2. copy settings.default.toml
$ cp configs/settings.default.toml configs/settings.toml
# 3. edit `configs/settings.toml`
# 3.1. you may need to modify in settings.toml
[server.docs]
# set `go-gin-wrapper` path
# this path must be chnaged first for specific environment
path = "${GOPATH}/src/github.com/hiromaily/go-gin-wrapper"
$ 4. start MySQL
$ docker-compose up mysql
# 5. make sure `go run` works
$ go run ./cmd/ginserver/ -f ./configs/settings.toml
# 6. unit test requires ${GOGIN_CONF} environment variable
- define proper path on `.envrc`
$ docker-compose build
$ docker-compose up
- configs/docker.toml
- docker-compose.yml
- docker-compose.override.yml
- Dockerfile
- ./build/docker/*
## Install
$ heroku create ginserver --buildpack heroku/go
# MySQL
$ heroku addons:create cleardb
$ heroku config | grep CLEARDB_DATABASE_URL
# Redis
$ heroku addons:create heroku-redis:hobby-dev -a ginserver
$ heroku config | grep REDIS
## Environment variable
$ heroku config:add ENC_KEY=xxxxx
$ heroku config:add ENC_IV=xxxxx
## Check
$ heroku config | grep CLEARDB_DATABASE_URL
$ heroku config | grep REDIS
$ heroku ps -a ginserver
## Deploy
$ git push -f heroku master
-
./configs/heroku.toml
is used to run server.
$ ginserver -f /app/configs/heroku.toml -crypto
NAME | Value | Explanation |
---|---|---|
GOGIN_CONF | xxxxx | config path, required in unit test |
ENC_KEY | xxxxx | encryption |
ENC_IV | xxxxx | encryption |
NAME | Value |
---|---|
PORT | 8080 |
- Heroku server use
PORT
automatically as environment variable.
Usage: ginserver [options...]
Options:
-f Toml file path
-p Overwriten server port number
-crypto if true, values in config file are encrypted
e.g.
$ ginserver -f /app/configs/yourfile.toml -crypto
See config file.
[profile]
enable = true
After running ginserver, acccess the below links.
[GIN-debug] GET /debug/pprof/
[GIN-debug] GET /debug/pprof/heap
[GIN-debug] GET /debug/pprof/goroutine
[GIN-debug] GET /debug/pprof/block
[GIN-debug] GET /debug/pprof/threadcreate
[GIN-debug] GET /debug/pprof/cmdline
[GIN-debug] GET /debug/pprof/profile
[GIN-debug] GET /debug/pprof/symbol
[GIN-debug] POST /debug/pprof/symbol
[GIN-debug] GET /debug/pprof/trace