本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.Unsubscribe方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.Unsubscribe方法的具體用法?Golang RedisLogger.Unsubscribe怎麽用?Golang RedisLogger.Unsubscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.RedisLogger
的用法示例。
在下文中一共展示了RedisLogger.Unsubscribe方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: wsPushHandler
//.........這裏部分代碼省略.........
//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":
var lat, lng float64
var locaddr string
for _, body := range event.Data.Body {
switch body.Type {
case "latlng":
//log.Println("latlng:", body.Content)
loc := strings.Split(body.Content, ",")
if len(loc) != 2 {
break
}
lat, _ = strconv.ParseFloat(loc[0], 64)
lng, _ = strconv.ParseFloat(loc[1], 64)
case "locaddr":
//log.Println("locaddr:", body.Content)
locaddr = body.Content
}
}
user.UpdateLocation(models.Location{Lat: lat, Lng: lng}, locaddr)
case "device":
for _, body := range event.Data.Body {
switch body.Type {
case "token":
token := body.Content
//log.Println("device token:", token)
user.AddDevice(token)
}
}
}
default:
log.Println("unhandled message type:", event.Type)
}
}
}(conn)
for {
switch v := psc.Receive().(type) {
case redis.Message:
//log.Printf("%s: message: %s\n", v.Channel, v.Data)
event := &models.Event{}
if err := json.Unmarshal(v.Data, event); err != nil {
log.Println("parse push message error:", err)
continue
}
// subscribe group
if event.Data.Type == models.EventSub && event.Data.From == user.Id {
if err := redisLogger.Subscribe(psc, event.Data.To); err != nil {
log.Println(err)
}
continue
}
// unsubscribe group
if event.Data.Type == models.EventUnsub && event.Data.From == user.Id {
if err := redisLogger.Unsubscribe(psc, event.Data.To); err != nil {
log.Println(err)
}
continue
}
if err := conn.WriteMessage(websocket.TextMessage, v.Data); err != nil {
log.Println(err)
return
}
case redis.Subscription:
//log.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
case error:
//log.Println(v)
return
}
}
}