定时更新数据库访客状态

pull/23/head
taoshihan1991 4 years ago
parent f0ea379b16
commit 7bcdc4ef27

@ -19,10 +19,7 @@ const Dir = "config/"
const AccountConf = Dir + "account.json" const AccountConf = Dir + "account.json"
const MysqlConf = Dir + "mysql.json" const MysqlConf = Dir + "mysql.json"
const MailConf = Dir + "mail.json" const MailConf = Dir + "mail.json"
const LangConf = Dir + "language.json"
const MainConf = Dir + "config.json" const MainConf = Dir + "config.json"
const WeixinToken = ""
const ServerJiang = ""
func init() { func init() {
//配置文件 //配置文件

@ -4,7 +4,7 @@ type Language struct {
WebCopyRight string WebCopyRight string
MainIntro string MainIntro string
Send string Send string
Notice string Notice, Maintech string
IndexSubIntro, IndexVisitors, IndexAgent, IndexDocument, IndexOnlineChat string IndexSubIntro, IndexVisitors, IndexAgent, IndexDocument, IndexOnlineChat string
} }
@ -22,6 +22,7 @@ func CreateLanguage(lang string) *Language {
IndexOnlineChat: "Lets chat. - We're online", IndexOnlineChat: "Lets chat. - We're online",
Send: "Send", Send: "Send",
Notice: "Hello and welcome to go-fly - how can we help?", Notice: "Hello and welcome to go-fly - how can we help?",
Maintech: "Main technical architecture",
} }
} }
if lang == "cn" { if lang == "cn" {
@ -35,6 +36,7 @@ func CreateLanguage(lang string) *Language {
IndexOnlineChat: "在线咨询", IndexOnlineChat: "在线咨询",
Send: "发送", Send: "发送",
Notice: "欢迎您访问go-fly有什么我能帮助您的", Notice: "欢迎您访问go-fly有什么我能帮助您的",
Maintech: "主要技术架构",
} }
} }
return language return language

@ -52,7 +52,7 @@ func init() {
ReadBufferSize: 1024, ReadBufferSize: 1024,
WriteBufferSize: 1024, WriteBufferSize: 1024,
} }
//go sendPingUpdateStatus() go UpdateVisitorStatusCron()
go singleBroadcaster() go singleBroadcaster()
//go sendPingOnlineUsers() //go sendPingOnlineUsers()
//sendPingToClient() //sendPingToClient()
@ -173,16 +173,19 @@ func sendPingToClient() {
} }
//定时给更新数据库状态 //定时给更新数据库状态
func sendPingUpdateStatus() { func UpdateVisitorStatusCron() {
for { for {
visitors := models.FindVisitorsOnline() visitors := models.FindVisitorsOnline()
for _, visitor := range visitors { for _, visitor := range visitors {
if visitor.VisitorId == "" {
continue
}
_, ok := clientList[visitor.VisitorId] _, ok := clientList[visitor.VisitorId]
if !ok { if !ok {
models.UpdateVisitorStatus(visitor.VisitorId, 0) models.UpdateVisitorStatus(visitor.VisitorId, 0)
} }
} }
time.Sleep(20 * time.Second) time.Sleep(60 * time.Second)
} }
} }

@ -7,7 +7,7 @@ import (
) )
func Index(c *gin.Context) { func Index(c *gin.Context) {
c.Redirect(302, "/index") c.Redirect(302, "/index/en")
} }
//首页跳转 //首页跳转

@ -5,7 +5,10 @@ import (
) )
func SetLanguage(c *gin.Context) { func SetLanguage(c *gin.Context) {
lang := c.Query("lang") var lang string
if lang = c.Param("lang"); lang == "" {
lang = c.Query("lang")
}
if lang == "" || lang != "cn" { if lang == "" || lang != "cn" {
lang = "en" lang = "en"
} }

@ -7,7 +7,7 @@ import (
) )
func InitViewRouter(engine *gin.Engine) { func InitViewRouter(engine *gin.Engine) {
engine.GET("/index", tmpl.PageIndex) engine.GET("/index/:lang", middleware.SetLanguage, tmpl.PageIndex)
engine.GET("/login", tmpl.PageLogin) engine.GET("/login", tmpl.PageLogin)
engine.GET("/chat_page", middleware.SetLanguage, tmpl.PageChat) engine.GET("/chat_page", middleware.SetLanguage, tmpl.PageChat)
engine.GET("/chatIndex", middleware.SetLanguage, tmpl.PageChat) engine.GET("/chatIndex", middleware.SetLanguage, tmpl.PageChat)

@ -75,49 +75,53 @@
margin: 30px auto; margin: 30px auto;
} }
.footer { .footer {
clear: both;
background-color: #f7fbfd; background-color: #f7fbfd;
width: 100%; width: 100%;
padding: 40px 150px; padding: 40px 150px;
box-sizing: border-box; box-sizing: border-box;
} }
.try{
display: inline-block;
padding: 10px 20px;
background: #519eff;
color: #fff;
border-radius: 5px;
cursor: pointer;
margin-right: 20px;
text-decoration: none;
}
.try:hover {
transform: translateY(-1px);
background: #318cff;
box-shadow: 0 7px 14px rgba(50,50,50,.1), 0 3px 6px rgba(0,0,0,.1);
}
.copyright{ .copyright{
color: #6c757d; color: #6c757d;
text-align: center; text-align: center;
margin: 60px 0; margin: 60px 0;
} }
.codeDeploy{ .mainTechLeft{
color: #fff; width: 300px;
width: 1000px; float: left;
margin: 0 auto; }
background: #555555; .mainTechLeft h1{
padding: 10px; font-size: 34px;
white-space: pre-wrap; margin: 0;
word-wrap: break-word; line-height: 48px;
line-height: 24px; color: #555;
font-weight: 500;
font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,SimSun,sans-serif;
}
.mainTechLeft p{
font-size: 18px;
line-height: 28px;
color: #888;
margin: 10px 0 5px;
}
.floatRight{
width: 700px;
border: 1px solid #e1e1e1;
padding: 4px;
margin-top: 35px;
display: block;
float: right;
} }
</style> </style>
</head> </head>
<header class="header"> <header class="header">
<div class="container"> <div class="container">
<h1><a href="/index">GO-FLY</a></h1> <h1><a href="/index">GO-FLY</a></h1>
<a class="navBtn" href="/index?lang=en">English (United States)</a> <a class="navBtn" href="/index/en">English (United States)</a>
<a class="navBtn" href="/index?lang=cn">中文版 (简体)</a> <a class="navBtn" href="/index/cn">中文版 (简体)</a>
<a class="navBtn" href="https://github.com/taoshihan1991/go-fly" target="_blank">Github</a>
<a class="navBtn" href="/login">{{.AgentBtn}}</a> <a class="navBtn" href="/login">{{.AgentBtn}}</a>
<a class="navBtn" href="/docs/index.html" target="_blank">{{.Document}}</a>
</div> </div>
</header> </header>
<div class="banner"> <div class="banner">
@ -128,30 +132,32 @@
{{if eq .Lang "en"}} {{if eq .Lang "en"}}
<img src="/static/images/intro3.png"/> <img src="/static/images/intro3.png"/>
{{else}} {{else}}
<img src="/static/images/intro1.jpg"/> <img src="/static/images/intro1.jpg"/>
{{end}} {{end}}
</div> </div>
<pre class="codeDeploy"> <div class="container">
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt; <div class="mainTechLeft">
&lt;script src=&quot;https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js&quot;&gt;&lt;/script&gt; <h1>{{.Maintech}}</h1>
&lt;link href=&quot;https://gofly.sopans.com/static/css/gofly-front.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt; <p>github.com/dgrijalva/jwt-go</p>
&lt;div id=&quot;launchButton&quot; class=&quot;launchButton&quot;&gt; <p>github.com/gin-gonic/gin</p>
&lt;svg x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 27 21.9&quot; aria-labelledby=&quot;title desc&quot; role=&quot;img&quot; class=&quot;xhl-launch-button-svg&quot;&gt;&lt;title&gt;Chat Icon &lt;/title&gt;&lt;desc&gt;three small dots to indicate that an agent is available to chat&lt;/desc&gt;&lt;path fill=&quot;#ffffff&quot; d=&quot;M23.2,0L2.6,1.7C1,1.9,0,3.2,0,4.9v8c0,1.6,0.8,3,2.4,3.1l5.3,0.5c0,0,1,1.6,0.3,3.2C7.2,21.3,6,21.9,6,21.9 c4.2,0,6.6-3.1,7.8-4.9l9.4,0.7c1.8,0.2,3.8-1.3,3.8-3.1V3.1C27,1.3,25-0.1,23.2,0z M6.4,10.1c-0.9,0-1.7-0.7-1.7-1.7 c0-0.9,0.7-1.7,1.7-1.7C7.3,6.8,8,7.5,8,8.5C8,9.4,7.3,10.1,6.4,10.1z M13.2,10.1c-0.9,0-1.7-0.7-1.7-1.7c0-0.9,0.7-1.7,1.7-1.7 c0.9,0,1.7,0.7,1.7,1.7C14.8,9.4,14.1,10.1,13.2,10.1z M19.9,10.1c-0.9,0-1.7-0.7-1.7-1.7c0-0.9,0.7-1.7,1.7-1.7 c0.9,0,1.7,0.7,1.7,1.7C21.6,9.4,20.9,10.1,19.9,10.1z&quot;&gt;&lt;/path&gt;&lt;/svg&gt; <p> github.com/go-sql-driver/mysql</p>
&lt;div class=&quot;launchButtonText&quot;&gt; <p> github.com/gobuffalo/packr/v2</p>
Chat with us <p> github.com/gorilla/websocket</p>
&lt;/div&gt; <p> github.com/ipipdotnet/ipdb-go</p>
&lt;/div&gt; <p> github.com/jinzhu/gorm</p>
&lt;script&gt; <p> github.com/satori/go.uuid</p>
var GOFLY_URL=&quot;https://gofly.sopans.com&quot;; <p> github.com/spf13/cobra</p>
&lt;/script&gt; <p> github.com/swaggo/gin-swagger</p>
&lt;script src=&quot;https://gofly.sopans.com/static/js/gofly-front.js&quot;&gt;&lt;/script&gt; <p> github.com/swaggo/swag
</pre> </p>
</div>
<img src="/static/images/admin.png" class="floatRight"/>
</div>
<footer class="footer"> <footer class="footer">
<div class="container"> <div class="container">
<a class="try" href="/docs/index.html" target="_blank">{{.Document}}</a>
<a class="try" href="/login?lang={{.Lang}}" target="_blank">{{.AgentBtn}}</a>
<a class="try" href="https://github.com/taoshihan1991/go-fly" target="_blank">Github</a>
</div> </div>
<div class="copyright"> <div class="copyright">
{{.Copyright}}&copy; 2020 {{.Copyright}}&copy; 2020

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

@ -44,11 +44,8 @@ func (obj *CommonHtml) Display(file string, data interface{}) {
//首页 //首页
func PageIndex(c *gin.Context) { func PageIndex(c *gin.Context) {
lang := c.Query("lang") lang, _ := c.Get("lang")
if lang == "" || lang != "cn" { language := config.CreateLanguage(lang.(string))
lang = "en"
}
language := config.CreateLanguage(lang)
c.HTML(http.StatusOK, "index.html", gin.H{ c.HTML(http.StatusOK, "index.html", gin.H{
"Copyright": language.WebCopyRight, "Copyright": language.WebCopyRight,
"WebDesc": language.MainIntro, "WebDesc": language.MainIntro,
@ -58,6 +55,7 @@ func PageIndex(c *gin.Context) {
"AgentBtn": language.IndexAgent, "AgentBtn": language.IndexAgent,
"OnlineChat": language.IndexOnlineChat, "OnlineChat": language.IndexOnlineChat,
"IndexSend": language.Send, "IndexSend": language.Send,
"Maintech": language.Maintech,
"Lang": lang, "Lang": lang,
}) })
} }

Loading…
Cancel
Save