本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.DelOnlineUser方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.DelOnlineUser方法的具體用法?Golang RedisLogger.DelOnlineUser怎麽用?Golang RedisLogger.DelOnlineUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.RedisLogger
的用法示例。
在下文中一共展示了RedisLogger.DelOnlineUser方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: logoutHandler
func logoutHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
redis.DelOnlineUser(p.TokenId())
if len(user.Devs) > 0 {
user.RmDevice(user.Devs[0])
}
writeResponse(request.RequestURI, resp, nil, nil)
}
示例2: wsPushHandler
func wsPushHandler(request *http.Request, resp http.ResponseWriter, redisLogger *models.RedisLogger) {
conn, err := upgrader.Upgrade(resp, request, nil)
if err != nil {
conn.WriteJSON(errors.NewError(errors.HttpError, err.Error()))
return
}
defer conn.Close()
r := wsAuthResp{}
var auth wsAuth
conn.ReadJSON(&auth)
//log.Println("check token:", auth.Token)
if !checkTokenValid(auth.Token) {
//log.Println("check token valid")
redisLogger.DelOnlineUser(auth.Token)
conn.WriteJSON(r)
return
}
uid := redisLogger.OnlineUser(auth.Token)
user := &models.Account{}
if find, _ := user.FindByUserid(uid); !find || user.TimeLimit < 0 {
r.TimeLimit = user.TimeLimit
conn.WriteJSON(r)
return
}
//redisLogger.LogLogin(user.Id)
days := user.LoginDays
loginCount := user.LoginCount + 1
d := nowDate()
if user.LastLogin.Unix() < d.Unix() { // check wether first time login of one day
days++
if user.LastLogin.Unix() < d.Unix()-24*3600 {
days = 1
}
loginCount = 1
}
//fmt.Println(uid, "loginCount", loginCount)
user.SetLastLogin(days, loginCount, time.Now())
r.Userid = uid
r.LastLog = user.LastLogin.Unix()
r.LoginCount = loginCount
if err := conn.WriteJSON(r); err != nil {
return
}
if len(uid) == 0 {
return
}
redisLogger.LogVisitor(user.Id)
psc := redisLogger.PubSub(user.Id)
go func(conn *websocket.Conn) {
//wg.Add(1)
//defer log.Println("ws thread closed")
//defer wg.Done()
redisLogger.SetOnline(user.Id, user.Actor, true, 0)
start := time.Now()
defer psc.Close()
for {
event := &models.Event{}
err := conn.ReadJSON(event)
if err != nil {
//log.Println(err)
dur := int64(time.Since(start) / time.Second)
redisLogger.SetOnline(user.Id, user.Actor, false, dur)
user.UpdateStat(models.StatOnlineTime, dur)
return
}
//log.Println("recv msg:", event.Type)
switch event.Type {
case models.EventMsg:
m := &models.Message{
From: event.Data.From,
To: event.Data.To,
Body: event.Data.Body,
Time: time.Now(),
}
if event.Data.Type == models.EventChat || event.Data.Type == models.EventGChat {
m.Type = event.Data.Type
m.Save()
event.Data.Id = m.Id.Hex()
event.Time = m.Time.Unix()
redisLogger.PubMsg(m.Type, m.To, event.Bytes())
}
case models.EventStatus:
//fmt.Println(user.Id, event.Data.Body)
switch event.Data.Type {
case "loc":
//.........這裏部分代碼省略.........