Commit 2698a9e7 authored by szh's avatar szh

up

parent 3a943f59
# Go Gin Example [![rcard](https://goreportcard.com/badge/chain33-pai)](https://goreportcard.com/report/chain33-pai) [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/chain33-pai) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/EDDYCJY/go-gin-example/master/LICENSE)
An example of gin contains many useful features
[简体中文](https://chain33-pai/blob/master/README_ZH.md)
## Installation
```
$ go get chain33-pai
```
## How to run
### Required ### Required
- Mysql - Mysql
- Redis
### Ready ### Ready
Create a **blog database** and import [SQL](https://chain33-pai/blob/master/docs/sql/blog.sql) Create a **blog database** and import [SQL](docs/sql/raspberry.sql)
### Conf ### Conf
...@@ -44,7 +32,7 @@ IdleTimeout = 200 ...@@ -44,7 +32,7 @@ IdleTimeout = 200
### Run ### Run
``` ```
$ cd $GOPATH/src/go-gin-example $ cd $GOPATH/src/chain33-pai
$ go run main.go $ go run main.go
``` ```
...@@ -56,34 +44,16 @@ Project information and existing API ...@@ -56,34 +44,16 @@ Project information and existing API
- using env: export GIN_MODE=release - using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode) - using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET /auth --> chain33-pai/routers/api.GetAuth (3 handlers) [GIN-debug] GET /pai/devdetail --> chain33-pai/routers/api/v1.GetDevdetail (4 handlers)
[GIN-debug] GET /swagger/*any --> chain33-pai/vendor/github.com/swaggo/gin-swagger.WrapHandler.func1 (3 handlers) [GIN-debug] POST /pai/devstatus --> chain33-pai/routers/api/v1.GetDevstatus (4 handlers)
[GIN-debug] GET /api/v1/tags --> chain33-pai/routers/api/v1.GetTags (4 handlers)
[GIN-debug] POST /api/v1/tags --> chain33-pai/routers/api/v1.AddTag (4 handlers)
[GIN-debug] PUT /api/v1/tags/:id --> chain33-pai/routers/api/v1.EditTag (4 handlers)
[GIN-debug] DELETE /api/v1/tags/:id --> chain33-pai/routers/api/v1.DeleteTag (4 handlers)
[GIN-debug] GET /api/v1/articles --> chain33-pai/routers/api/v1.GetArticles (4 handlers)
[GIN-debug] GET /api/v1/articles/:id --> chain33-pai/routers/api/v1.GetArticle (4 handlers)
[GIN-debug] POST /api/v1/articles --> chain33-pai/routers/api/v1.AddArticle (4 handlers)
[GIN-debug] PUT /api/v1/articles/:id --> chain33-pai/routers/api/v1.EditArticle (4 handlers)
[GIN-debug] DELETE /api/v1/articles/:id --> chain33-pai/routers/api/v1.DeleteArticle (4 handlers)
Listening port is 8000 Listening port is 8000
Actual pid is 4393 Actual pid is 4393
``` ```
Swagger doc
## crontab -l
![image](https://i.imgur.com/bVRLTP4.jpg) chain33-pai程序自启动
*/1 * * * * /home/pi/chain33-pai/startup.sh
## Features 钱包程序自启动
*/1 * * * * /home/pi/chain33-pai/auto.sh >> /home/pi/chain33-pai/auto.log
- RESTful API \ No newline at end of file
- Gorm
- Swagger
- logging
- Jwt-go
- Gin
- Graceful restart or stop (fvbock/endless)
- App configurable
- Cron
- Redis
\ No newline at end of file
# Go Gin Example [![rcard](https://goreportcard.com/badge/chain33-pai)](https://goreportcard.com/report/chain33-pai) [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/chain33-pai) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/EDDYCJY/go-gin-example/master/LICENSE)
`gin` 的一个例子,包含许多有用特性
## 目录
本项目提供 [Gin实践](https://segmentfault.com/a/1190000013297625) 的连载示例代码
1. [Gin实践 连载一 Golang介绍与环境安装](https://book.eddycjy.com/golang/gin/install.html)
2. [Gin实践 连载二 搭建Blog API's(一)](https://book.eddycjy.com/golang/gin/api-01.html)
3. [Gin实践 连载三 搭建Blog API's(二)](https://book.eddycjy.com/golang/gin/api-02.html)
4. [Gin实践 连载四 搭建Blog API's(三)](https://book.eddycjy.com/golang/gin/api-03.html)
5. [Gin实践 连载五 使用JWT进行身份校验](https://book.eddycjy.com/golang/gin/jwt.html)
6. [Gin实践 连载六 编写一个简单的文件日志](https://book.eddycjy.com/golang/gin/log.html)
7. [Gin实践 连载七 Golang优雅重启HTTP服务](https://book.eddycjy.com/golang/gin/reload-http.html)
8. [Gin实践 连载八 为它加上Swagger](https://book.eddycjy.com/golang/gin/swagger.html)
9. [Gin实践 连载九 将Golang应用部署到Docker](https://book.eddycjy.com/golang/gin/golang-docker.html)
10. [Gin实践 连载十 定制 GORM Callbacks](https://book.eddycjy.com/golang/gin/gorm-callback.html)
11. [Gin实践 连载十一 Cron定时任务](https://book.eddycjy.com/golang/gin/cron.html)
12. [Gin实践 连载十二 优化配置结构及实现图片上传](https://book.eddycjy.com/golang/gin/config-upload.html)
13. [Gin实践 连载十三 优化你的应用结构和实现Redis缓存](https://book.eddycjy.com/golang/gin/application-redis.html)
14. [Gin实践 连载十四 实现导出、导入 Excel](https://book.eddycjy.com/golang/gin/excel.html)
15. [Gin实践 连载十五 生成二维码、合并海报](https://book.eddycjy.com/golang/gin/image.html)
16. [Gin实践 连载十六 在图片上绘制文字](https://book.eddycjy.com/golang/gin/font.html)
17. [Gin实践 连载十七 用 Nginx 部署 Go 应用](https://book.eddycjy.com/golang/gin/nginx.html)
18. [Gin实践 番外 Golang交叉编译](https://book.eddycjy.com/golang/gin/cgo.html)
19. [Gin实践 番外 请入门 Makefile](https://book.eddycjy.com/golang/gin/makefile.html)
## 安装
```
$ go get chain33-pai
```
## 如何运行
### 必须
- Mysql
- Redis
### 准备
创建一个 `blog` 数据库,并且导入建表的 [SQL](https://chain33-pai/blob/master/docs/sql/blog.sql)
### 配置
你应该修改 `conf/app.ini` 配置文件
```
[database]
Type = mysql
User = root
Password = rootroot
Host = 127.0.0.1:3306
Name = blog
TablePrefix = blog_
[redis]
Host = 127.0.0.1:6379
Password =
MaxIdle = 30
MaxActive = 30
IdleTimeout = 200
...
```
### 运行
```
$ cd $GOPATH/src/go-gin-example
$ go run main.go
```
项目的运行信息和已存在的 API's
```
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET /auth --> chain33-pai/routers/api.GetAuth (3 handlers)
[GIN-debug] GET /swagger/*any --> chain33-pai/vendor/github.com/swaggo/gin-swagger.WrapHandler.func1 (3 handlers)
[GIN-debug] GET /api/v1/tags --> chain33-pai/routers/api/v1.GetTags (4 handlers)
[GIN-debug] POST /api/v1/tags --> chain33-pai/routers/api/v1.AddTag (4 handlers)
[GIN-debug] PUT /api/v1/tags/:id --> chain33-pai/routers/api/v1.EditTag (4 handlers)
[GIN-debug] DELETE /api/v1/tags/:id --> chain33-pai/routers/api/v1.DeleteTag (4 handlers)
[GIN-debug] GET /api/v1/articles --> chain33-pai/routers/api/v1.GetArticles (4 handlers)
[GIN-debug] GET /api/v1/articles/:id --> chain33-pai/routers/api/v1.GetArticle (4 handlers)
[GIN-debug] POST /api/v1/articles --> chain33-pai/routers/api/v1.AddArticle (4 handlers)
[GIN-debug] PUT /api/v1/articles/:id --> chain33-pai/routers/api/v1.EditArticle (4 handlers)
[GIN-debug] DELETE /api/v1/articles/:id --> chain33-pai/routers/api/v1.DeleteArticle (4 handlers)
Listening port is 8000
Actual pid is 4393
```
Swagger 文档
![image](https://i.imgur.com/bVRLTP4.jpg)
## 特性
- RESTful API
- Gorm
- Swagger
- logging
- Jwt-go
- Gin
- Graceful restart or stop (fvbock/endless)
- App configurable
- Cron
- Redis
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment