是否开启gzip

This commit is contained in:
xing 2022-10-07 23:48:42 +08:00
parent 6704b5b486
commit 111f83ec88
4 changed files with 13 additions and 6 deletions

View File

@ -51,3 +51,5 @@ singleIpSearchNum: 10
maxPostIdCacheTime: 1h maxPostIdCacheTime: 1h
# 用户信息缓存时间 # 用户信息缓存时间
userInfoCacheTime: 24h userInfoCacheTime: 24h
# Gzip
gzip: false

5
go.mod
View File

@ -3,6 +3,9 @@ module github/fthvgb1/wp-go
go 1.18 go 1.18
require ( require (
github.com/dlclark/regexp2 v1.7.0
github.com/gin-contrib/gzip v0.0.6
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/sessions v0.0.5 github.com/gin-contrib/sessions v0.0.5
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
@ -11,8 +14,6 @@ require (
) )
require ( require (
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/gin-contrib/pprof v1.4.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect

View File

@ -1,6 +1,7 @@
package route package route
import ( import (
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/pprof" "github.com/gin-contrib/pprof"
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie" "github.com/gin-contrib/sessions/cookie"
@ -10,6 +11,7 @@ import (
"github/fthvgb1/wp-go/middleware" "github/fthvgb1/wp-go/middleware"
"github/fthvgb1/wp-go/static" "github/fthvgb1/wp-go/static"
"github/fthvgb1/wp-go/templates" "github/fthvgb1/wp-go/templates"
"github/fthvgb1/wp-go/vars"
"html/template" "html/template"
"net/http" "net/http"
"time" "time"
@ -29,10 +31,11 @@ func SetupRouter() *gin.Engine {
}).SetTemplate() }).SetTemplate()
r.Use(gin.Logger(), middleware.FlowLimit(), gin.Recovery(), middleware.SetStaticFileCache) r.Use(gin.Logger(), middleware.FlowLimit(), gin.Recovery(), middleware.SetStaticFileCache)
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用 //gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
/*r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{ if vars.Conf.Gzip {
"/wp-includes/", "/wp-content/", r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{
})))*/ "/wp-includes/", "/wp-content/",
})))
}
f := static.Fs{FS: static.FsEx, Path: "wp-includes"} f := static.Fs{FS: static.FsEx, Path: "wp-includes"}
r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsEx)) r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsEx))
r.StaticFS("/wp-includes", http.FS(f)) r.StaticFS("/wp-includes", http.FS(f))

View File

@ -30,6 +30,7 @@ type Config struct {
SingleIpSearchNum int64 `yaml:"singleIpSearchNum"` SingleIpSearchNum int64 `yaml:"singleIpSearchNum"`
MaxPostIdCacheTime time.Duration `yaml:"maxPostIdCacheTime"` MaxPostIdCacheTime time.Duration `yaml:"maxPostIdCacheTime"`
UserInfoCacheTime time.Duration `yaml:"userInfoCacheTime"` UserInfoCacheTime time.Duration `yaml:"userInfoCacheTime"`
Gzip bool `yaml:"gzip"`
} }
type Mysql struct { type Mysql struct {