mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-15 10:52:26 +08:00
update vendor and use single static
This commit is contained in:
55
front.go
55
front.go
@@ -20,13 +20,47 @@ import (
|
||||
func Filter() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 过滤黑名单
|
||||
BlackFilter(c)
|
||||
if BlackFilter(c) {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
// 重定向
|
||||
if Redirect(c) {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
// 用户cookie,用于统计
|
||||
UserCookie(c)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单过滤
|
||||
func BlackFilter(c *gin.Context) bool {
|
||||
ip := c.ClientIP()
|
||||
if setting.BlackIP[ip] {
|
||||
c.String(http.StatusForbidden, "Your IP is blacklisted.")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 重定向
|
||||
func Redirect(c *gin.Context) bool {
|
||||
fmt.Println("scheme=======", c.Request.URL.Scheme)
|
||||
if setting.Conf.Mode.EnableHttps && c.Request.ProtoMajor == 1 {
|
||||
var port string
|
||||
if strings.Contains(c.Request.Host, ":") {
|
||||
port = fmt.Sprintf(":%d", setting.Conf.Mode.HttpsPort)
|
||||
}
|
||||
c.Redirect(http.StatusMovedPermanently, "https://"+setting.Conf.Mode.Domain+port+c.Request.RequestURI)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 用户识别
|
||||
func UserCookie(c *gin.Context) {
|
||||
cookie, err := c.Cookie("u")
|
||||
@@ -35,15 +69,6 @@ func UserCookie(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单过滤
|
||||
func BlackFilter(c *gin.Context) {
|
||||
ip := c.ClientIP()
|
||||
if setting.BlackIP[ip] {
|
||||
c.Abort()
|
||||
c.String(http.StatusForbidden, "Your IP is blacklisted.")
|
||||
}
|
||||
}
|
||||
|
||||
// 解析静态文件版本
|
||||
func StaticVersion(c *gin.Context) (version int) {
|
||||
cookie, err := c.Request.Cookie("v")
|
||||
@@ -61,7 +86,7 @@ func GetBase() gin.H {
|
||||
"CopyYear": time.Now().Year(),
|
||||
"BTitle": Ei.BTitle,
|
||||
"BeiAn": Ei.BeiAn,
|
||||
"Domain": setting.Conf.Mode.Domains[0],
|
||||
"Domain": setting.Conf.Mode.Domain,
|
||||
"Kodo": setting.Conf.Kodo,
|
||||
"ShortName": setting.Conf.Disqus.ShortName,
|
||||
}
|
||||
@@ -232,6 +257,14 @@ func HandleSitemap(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/sitemap.xml")
|
||||
}
|
||||
|
||||
func HandleCrossDomain(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/crossdomain.xml")
|
||||
}
|
||||
|
||||
func HandleFavicon(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/favicon.ico")
|
||||
}
|
||||
|
||||
// 服务端推送谷歌统计
|
||||
func HandleBeacon(c *gin.Context) {
|
||||
ua := c.Request.UserAgent()
|
||||
|
||||
Reference in New Issue
Block a user