定时更新数据库访客状态

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

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

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

@ -52,7 +52,7 @@ func init() {
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
//go sendPingUpdateStatus()
go UpdateVisitorStatusCron()
go singleBroadcaster()
//go sendPingOnlineUsers()
//sendPingToClient()
@ -173,16 +173,19 @@ func sendPingToClient() {
}
//定时给更新数据库状态
func sendPingUpdateStatus() {
func UpdateVisitorStatusCron() {
for {
visitors := models.FindVisitorsOnline()
for _, visitor := range visitors {
if visitor.VisitorId == "" {
continue
}
_, ok := clientList[visitor.VisitorId]
if !ok {
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) {
c.Redirect(302, "/index")
c.Redirect(302, "/index/en")
}
//首页跳转

@ -5,7 +5,10 @@ import (
)
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" {
lang = "en"
}

@ -7,7 +7,7 @@ import (
)
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("/chat_page", middleware.SetLanguage, tmpl.PageChat)
engine.GET("/chatIndex", middleware.SetLanguage, tmpl.PageChat)

@ -75,49 +75,53 @@
margin: 30px auto;
}
.footer {
clear: both;
background-color: #f7fbfd;
width: 100%;
padding: 40px 150px;
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{
color: #6c757d;
text-align: center;
margin: 60px 0;
}
.codeDeploy{
color: #fff;
width: 1000px;
margin: 0 auto;
background: #555555;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
line-height: 24px;
.mainTechLeft{
width: 300px;
float: left;
}
.mainTechLeft h1{
font-size: 34px;
margin: 0;
line-height: 48px;
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>
</head>
<header class="header">
<div class="container">
<h1><a href="/index">GO-FLY</a></h1>
<a class="navBtn" href="/index?lang=en">English (United States)</a>
<a class="navBtn" href="/index?lang=cn">中文版 (简体)</a>
<a class="navBtn" href="/index/en">English (United States)</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="/docs/index.html" target="_blank">{{.Document}}</a>
</div>
</header>
<div class="banner">
@ -128,30 +132,32 @@
{{if eq .Lang "en"}}
<img src="/static/images/intro3.png"/>
{{else}}
<img src="/static/images/intro1.jpg"/>
<img src="/static/images/intro1.jpg"/>
{{end}}
</div>
<pre class="codeDeploy">
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;https://gofly.sopans.com/static/css/gofly-front.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt;
&lt;div id=&quot;launchButton&quot; class=&quot;launchButton&quot;&gt;
&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;
&lt;div class=&quot;launchButtonText&quot;&gt;
Chat with us
&lt;/div&gt;
&lt;/div&gt;
&lt;script&gt;
var GOFLY_URL=&quot;https://gofly.sopans.com&quot;;
&lt;/script&gt;
&lt;script src=&quot;https://gofly.sopans.com/static/js/gofly-front.js&quot;&gt;&lt;/script&gt;
</pre>
<div class="container">
<div class="mainTechLeft">
<h1>{{.Maintech}}</h1>
<p>github.com/dgrijalva/jwt-go</p>
<p>github.com/gin-gonic/gin</p>
<p> github.com/go-sql-driver/mysql</p>
<p> github.com/gobuffalo/packr/v2</p>
<p> github.com/gorilla/websocket</p>
<p> github.com/ipipdotnet/ipdb-go</p>
<p> github.com/jinzhu/gorm</p>
<p> github.com/satori/go.uuid</p>
<p> github.com/spf13/cobra</p>
<p> github.com/swaggo/gin-swagger</p>
<p> github.com/swaggo/swag
</p>
</div>
<img src="/static/images/admin.png" class="floatRight"/>
</div>
<footer class="footer">
<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 class="copyright">
{{.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) {
lang := c.Query("lang")
if lang == "" || lang != "cn" {
lang = "en"
}
language := config.CreateLanguage(lang)
lang, _ := c.Get("lang")
language := config.CreateLanguage(lang.(string))
c.HTML(http.StatusOK, "index.html", gin.H{
"Copyright": language.WebCopyRight,
"WebDesc": language.MainIntro,
@ -58,6 +55,7 @@ func PageIndex(c *gin.Context) {
"AgentBtn": language.IndexAgent,
"OnlineChat": language.IndexOnlineChat,
"IndexSend": language.Send,
"Maintech": language.Maintech,
"Lang": lang,
})
}

Loading…
Cancel
Save