Github:https://github.com/golang-collection/Go-RestfulAPI
本项目使用Go语言构建Restful API服务,项目采用gin构建,包括jwt,swagger,viper, zap, gorm, make,bash等模块,通过docker一键部署并且可以动态扩缩容实现负载均衡。
This project uses Go language to build Restful API services, and gin to build the project, including JWT, Swagger, Viper, Zap, Gorm, Make, bash and other modules. It can be deployed by docker with one key and dynamically expand capacity to achieve load balance.
You need to customize your config. Create the config.json file under conf folder.
The configuration sample is shown below
{
"mysql": {
"user": "",
"password": "",
"host": "",
"db_name": ""
},
"redis": {
"host": ""
},
"rabbitmq": {
"user": "",
"password": "",
"host": ""
}
}
Deployment projects offer the following two approaches:
Please open the command line prompt and execute the command below. Make sure you have installed docker-compose
in advance.
git clone [email protected]:golang-collection/Go-RestfulAPI.git
cd Go-RestfulAPI
make
docker-compose up -d
Next, you can look into the docker-compose.yml
(with detailed config params).
The make command generates a binary executable of the service from the Makefile.
Please use docker-compose
to one-click to start up. By doing so, you don’t even have to configure RabbitMQ , Reds, MySQ,ElasticSearch. Create a file named docker-compose.yml
and input the code below.
version: "3"
services:
web:
build:
context: .
dockerfile: Dockerfile
ports: ["8080"]
lb:
image: dockercloud/haproxy
links:
- web
ports:
- 80:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Then execute the command below, and the project will start up. Open the browser and enter http://localhost:80/swagger/index.html
to see the swagger UI interface.
docker-compose up
You can expand the service by following this command, and then the load balancer will automatically assign each request to each service.
docker-compose up --scale web=3 -d
cd Go-RestfulAPI
make
bash admin.sh start
You can check the health of the service by following the command
bash admin.sh status
MIT
Copyright © 2020 Knowledge-Precipitation-Tribe