Golang API starter using Gin and xorm.
- go (>= v1.10 recommended)
- dep
- docker & docker-compose
- nodemon for Live Reloading Development
npm i -g nodemon
# or if you prefer yarn
yarn global add nodemon
Copy .env.example
to .env
.
cp .env.example .env
dep ensure
Run Docker.
docker-compose up -d
Init Database.
sh ./fixtures/init_db.sh
Access Database using phpMyAdmin.
open http://localhost:9080/db_structure.php?db=go-gin-xorm-starter
Or, access Database using Adminer.
open http://localhost:10080/?server=mysql&username=root&pass=password
Start API server.
make start
get fruits using curl
.
curl http://localhost:3000/v1/fruits
post fruit using curl
.
curl -X POST \
-H 'Authorization:Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImlhdCI6MTUxNjIzOTAyMn0.hkDGuuaVbg2rBeEk3e97yUzl3Gp2UfD_hZO0dnjH6elS4WmxplQzXEXdOSvVaGFTxLpvwvTx11MT3PZzBUkoKR7WkGa76YdKiJGR-SZy7Zpdj6u1FdB9BGsIuvnfl0foX8En2JPV-EIA5Pm2fdy2hSGg1nzaPMekL8KeEJYjyi8' \
-d '{"name":"Lemon","price":144}' \
http://localhost:3000/v1/fruits
This sample JWT is generated here.
Stop Docker.
docker-compose down
Build.
docker build -t myimage/starter .
Run.
Use -e
and --env-file
option to give environment variables.
docker run -p 8888:80 --env-file .env -e DATABASE_HOST=mydbhost myimage/starter