當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RedisLogger.LogVisitor方法代碼示例

本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.LogVisitor方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.LogVisitor方法的具體用法?Golang RedisLogger.LogVisitor怎麽用?Golang RedisLogger.LogVisitor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ginuerzh/sports/models.RedisLogger的用法示例。


在下文中一共展示了RedisLogger.LogVisitor方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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":
//.........這裏部分代碼省略.........
開發者ID:shevilangle,項目名稱:sports,代碼行數:101,代碼來源:push.go


注:本文中的github.com/ginuerzh/sports/models.RedisLogger.LogVisitor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。