Browse Source

添加gin gzip压缩

zhangjq 6 years ago
parent
commit
bd54a76034
2 changed files with 7 additions and 6 deletions
  1. 3 0
      engine/apiengine.go
  2. 4 6
      models/model.go

+ 3 - 0
engine/apiengine.go

@@ -16,6 +16,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/xormplus/xorm"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+	"github.com/gin-contrib/gzip"
 )
 
 type ApiEngine struct {
@@ -52,6 +53,8 @@ func NewApiEngine(driverName, dataSourceName string, addr string) *ApiEngine {
 
 	engine.GinEngine = gin.Default()
 
+	engine.GinEngine.Use(gzip.Gzip(gzip.DefaultCompression))
+
 	//启动session
 	//store := sessions.NewCookieStore([]byte("secret"))
 	//engine.GinEngine.Use(sessions.Sessions("session", store))

+ 4 - 6
models/model.go

@@ -32,10 +32,8 @@ func SyncDb(db *xorm.Engine) {
 	if !config.AppConfig.SyncDb {
 		return
 	}
-	
-	for _, bean := range beans {
-		if err := db.Sync2(bean); err != nil {
-			fmt.Println(err)
-		}
-	}
+	err := db.Sync2(beans);
+    if err != nil {
+		fmt.Println(err)
+    }
 }