本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.PubMsg方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.PubMsg方法的具體用法?Golang RedisLogger.PubMsg怎麽用?Golang RedisLogger.PubMsg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.RedisLogger
的用法示例。
在下文中一共展示了RedisLogger.PubMsg方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: recvHeartHandler
func recvHeartHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(recvHeartForm)
// ws push
event := &models.Event{
Type: models.EventSystem,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventRecvHeart,
Id: user.Id,
From: user.Id,
To: form.Sender,
Body: []models.MsgBody{
{Type: "userid", Content: user.Id},
},
},
}
awards := Awards{}
if form.Accept {
redis.SetRelationship(user.Id, []string{form.Sender}, models.RelFriend, true)
event.Save()
redis.PubMsg(models.EventSystem, form.Sender, event.Bytes())
awards.Wealth = 1 * models.Satoshi
GiveAwards(user, awards, redis)
}
redis.SetHeartRecv(user.Id, false)
writeResponse(r.RequestURI, w, map[string]interface{}{"ExpEffect": awards}, nil)
}
示例2: followHandler
func followHandler(request *http.Request, resp http.ResponseWriter,
client *ApnClient, redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(relationshipForm)
for _, peer := range form.Userids {
if redis.Relationship(peer, user.Id) == models.RelBlacklist {
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.DbError, "對方已屏蔽了你!"))
return
}
}
redis.SetRelationship(user.Id, form.Userids, models.RelFollowing, form.Follow)
writeResponse(request.RequestURI, resp, map[string]interface{}{"ExpEffect": Awards{}}, nil)
for _, userid := range form.Userids {
u := &models.Account{}
u.FindByUserid(userid)
event := &models.Event{
Type: models.EventMsg,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventSub,
Id: user.Id + "-" + u.Id,
From: user.Id,
To: u.Id,
Body: []models.MsgBody{
{Type: "nikename", Content: user.Nickname},
{Type: "image", Content: user.Profile},
},
},
}
if form.Follow {
/*
if err := event.Save(); err == nil {
redis.IncrEventCount(u.Id, event.Data.Type, 1)
}
*/
event.Upsert()
event.Data.Body = append(event.Data.Body,
models.MsgBody{Type: "new_count", Content: "1"})
redis.PubMsg(models.EventMsg, u.Id, event.Bytes())
// apple push
if u.Push {
go sendApn(client, user.Nickname+"關注了你!", u.EventCount("", ""), u.Devs...)
}
} else {
//count := u.DelEvent(models.EventSub, user.Id, user.Id, u.Id)
//redis.IncrEventCount(u.Id, models.EventSub, -count)
event.Delete()
}
}
}
示例3: sendHeartHandler
func sendHeartHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(sendHeartForm)
receivers := redis.HeartReceivers(user.Id)
if len(receivers) == 0 {
writeResponse(r.RequestURI, w, nil, nil)
}
var target string
for _, recv := range receivers {
if recv != user.Id {
target = recv
break
}
}
// ws push
event := &models.Event{
Type: models.EventSystem,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventSendHeart,
Id: user.Id,
From: user.Id,
To: target,
Body: []models.MsgBody{
{Type: "record_id", Content: form.Record},
{Type: "userid", Content: user.Id},
},
},
}
if len(target) > 0 {
event.Save()
redis.PubMsg(models.EventSystem, target, event.Bytes())
redis.LogHeartSend(user.Id)
redis.SetHeartRecv(target, true)
}
writeResponse(r.RequestURI, w, nil, nil)
}
示例4: joinGroupHandler
func joinGroupHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(joinGroupForm)
redis.JoinGroup(user.Id, form.Gid, !form.Leave)
writeResponse(request.RequestURI, resp, nil, nil)
event := &models.Event{
Type: "message",
Data: models.EventData{
From: user.Id,
To: form.Gid,
},
}
if !form.Leave {
event.Data.Type = "subscribe"
} else {
event.Data.Type = "unsubscribe"
}
redis.PubMsg(event.Data.Type, user.Id, event.Bytes())
}
示例5: GiveAwards
func GiveAwards(user *models.Account, awards Awards, redis *models.RedisLogger) error {
if awards.Level < 0 || awards.Score < 0 {
panic("invalid level or score")
}
if _, err := sendCoin(user.Wallet.Addr, awards.Wealth); err != nil {
return err
}
redis.SendCoins(user.Id, awards.Wealth)
err := user.UpdateProps(models.Props{
Physical: awards.Physical,
Literal: awards.Literal,
Mental: awards.Mental,
//Wealth: awards.Wealth,
Score: awards.Score,
//Level: awards.Level,
})
if err != nil {
return err
}
if lvl := models.Score2Level(user.Props.Score + awards.Score); lvl > user.Level() {
// ws push
event := &models.Event{
Type: models.EventNotice,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventLevelUP,
To: user.Id,
},
}
event.Save()
redis.PubMsg(event.Type, event.Data.To, event.Bytes())
}
return nil
}
示例6: taskSharedHandler
func taskSharedHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(taskSharedForm)
u := &models.Account{}
u.FindByUserid(form.Sender)
// ws push
event := &models.Event{
Type: models.EventSystem,
Time: time.Now().Unix(),
Data: models.EventData{
Id: user.Id,
From: user.Id,
To: form.Sender,
},
}
var article *models.Article
switch form.Type {
case models.TaskRunning:
event.Data.Type = models.EventRunShared
article = &models.Article{
Author: user.Id,
PubTime: time.Now(),
Contents: []models.Segment{
{ContentType: "TEXT", ContentText: "我和" + u.Nickname + "約好一起跑步,有想一起參加的嗎?" +
"\n跑步地點: " + form.Addr +
"\n跑步時間: " + time.Unix(form.Time, 0).Format("2006-01-02 3:04 PM")},
{ContentType: "IMAGE", ContentText: form.Image},
},
}
case models.TaskPost:
article := &models.Article{}
if find, _ := article.FindById(form.ArticleId); find {
article.SetThumb(user.Id, true)
}
event.Data.Type = models.EventPostShared
case models.TaskGame:
event.Data.Type = models.EventPKShared
result := u.Nickname + " 主動PK " + user.Nickname + "大獲全勝。"
if u.Props.Score < user.Props.Score {
result = u.Nickname + " 主動PK " + user.Nickname + "大敗虧輸。"
}
article = &models.Article{
Author: user.Id,
Type: "pk",
PubTime: time.Now(),
Contents: []models.Segment{
{ContentType: "TEXT", ContentText: result},
{ContentType: "IMAGE", ContentText: form.Image},
},
}
default:
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
return
}
awards := Awards{}
if form.Accept {
redis.SetRelationship(user.Id, []string{form.Sender}, models.RelFriend, true)
event.Save()
redis.PubMsg(models.EventSystem, form.Sender, event.Bytes())
user.UpdateRatio(form.Type, true)
if article != nil {
article.Save()
}
awards.Wealth = 1 * models.Satoshi
GiveAwards(user, awards, redis)
}
redis.SetTaskShare(user.Id, false)
writeResponse(r.RequestURI, w, map[string]interface{}{"ExpEffect": awards}, nil)
}
示例7: taskShareHandler
func taskShareHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(taskShareForm)
if form.TaskId > len(models.NewTasks) {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
return
}
//task := models.NewTasks[form.TaskId]
// ws push
event := &models.Event{
Type: models.EventSystem,
Time: time.Now().Unix(),
Data: models.EventData{
//Type: models.EventRunShare,
Id: user.Id,
From: user.Id,
To: form.Userid,
},
}
switch form.Type {
case models.TaskRunning:
record, _ := user.LastRecord("run")
latlng := strconv.FormatFloat(form.Lat, 'f', 7, 64) + "," +
strconv.FormatFloat(form.Lng, 'f', 7, 64)
event.Data.Type = models.EventRunShare
event.Data.Body = []models.MsgBody{
{Type: "record_id", Content: record.Id.Hex()},
{Type: "latlng", Content: latlng},
{Type: "locaddr", Content: form.Addr},
{Type: "time", Content: strconv.FormatInt(form.Time, 10)},
{Type: "addr_image", Content: form.Image},
}
case models.TaskPost:
event.Data.Type = models.EventPostShare
article := user.LatestArticle()
event.Data.Body = []models.MsgBody{
{Type: "article_id", Content: article.Id.Hex()},
}
case models.TaskGame:
record, _ := user.LastRecord("run")
event.Data.Type = models.EventPKShare
event.Data.Body = []models.MsgBody{
{Type: "record_id", Content: record.Id.Hex()},
}
default:
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
return
}
event.Save()
redis.PubMsg(event.Type, event.Data.To, event.Bytes())
u := &models.Account{Id: form.Userid}
u.UpdateRatio(form.Type, false)
redis.SetTaskShare(form.Userid, true)
if _, err := consumeCoin(user.Wallet.Addr, form.Coin); err == nil {
redis.ConsumeCoins(user.Id, form.Coin)
}
writeResponse(r.RequestURI, w, nil, nil)
}
示例8: articleThumbHandler
func articleThumbHandler(request *http.Request, resp http.ResponseWriter,
client *ApnClient, redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(articleThumbForm)
article := &models.Article{}
if find, err := article.FindById(form.Id); !find {
e := errors.NewError(errors.NotExistsError, "文章不存在!")
if err != nil {
e = errors.NewError(errors.DbError)
}
writeResponse(request.RequestURI, resp, nil, e)
return
}
if redis.Relationship(article.Author, user.Id) == models.RelBlacklist {
writeResponse(request.RequestURI, resp, nil,
errors.NewError(errors.AccessError, "對方屏蔽了你!"))
return
}
if err := article.SetThumb(user.Id, form.Status); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
awards := Awards{}
if form.Status {
awards = Awards{Score: 1, Wealth: 1 * models.Satoshi}
GiveAwards(user, awards, redis)
}
writeResponse(request.RequestURI, resp, map[string]interface{}{"ExpEffect": awards}, nil)
author := &models.Account{Id: article.Author}
// ws push
event := &models.Event{
Type: models.EventArticle,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventThumb,
Id: article.Id.Hex(),
From: user.Id,
To: author.Id,
Body: []models.MsgBody{
{Type: "total_count", Content: strconv.Itoa(article.ThumbCount + 1)},
{Type: "image", Content: article.Image},
},
},
}
if form.Status {
author.FindByUserid(article.Author)
/*
if err := event.Save(); err == nil {
redis.IncrEventCount(article.Author, event.Data.Type, 1)
}
*/
event.Upsert()
event.Data.Body = append(event.Data.Body,
models.MsgBody{Type: "new_count",
Content: strconv.Itoa(models.EventCount(event.Data.Type, event.Data.Id, event.Data.To))})
redis.PubMsg(models.EventArticle, article.Author, event.Bytes())
// apple push
if author.Push {
go sendApn(client, user.Nickname+"讚了你的主題!", author.EventCount("", ""), author.Devs...)
}
} else {
//count := author.DelEvent(models.EventThumb, article.Id.Hex(), user.Id, author.Id)
//redis.IncrEventCount(author.Id, models.EventThumb, -count)
event.Delete()
}
//user.UpdateAction(ActThumb, nowDate())
}
示例9: newArticleHandler
func newArticleHandler(request *http.Request, resp http.ResponseWriter,
client *ApnClient, redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(newArticleForm)
article := &models.Article{
Author: user.Id,
Contents: form.Contents,
PubTime: time.Now(),
Parent: form.Parent,
//Tags: form.Tags,
Loc: form.Location,
Type: form.Type,
}
article.Title, article.Images = articleCover(form.Contents)
if len(article.Images) > 0 {
article.Image = article.Images[0]
}
/*
if len(article.Tags) == 0 {
article.Tags = []string{"SPORT_LOG"}
}
*/
awards := Awards{}
parent := &models.Article{}
if len(form.Parent) > 0 {
if find, err := parent.FindById(form.Parent); !find {
e := errors.NewError(errors.NotExistsError, "文章不存在!")
if err != nil {
e = errors.NewError(errors.DbError)
}
writeResponse(request.RequestURI, resp, nil, e)
return
}
if redis.Relationship(parent.Author, user.Id) == models.RelBlacklist {
writeResponse(request.RequestURI, resp, nil,
errors.NewError(errors.AccessError, "對方屏蔽了你!"))
return
}
awards = Awards{Literal: 1 + user.Level(), Score: 1 + user.Level()}
} else {
if user.Stat != nil && user.Stat.LastArticleTime < nowDate().Unix() {
awards = Awards{Literal: 2 + user.Level(), Wealth: 2 * models.Satoshi, Score: 2 + user.Level()}
}
user.UpdateStat(models.StatLastArticleTime, time.Now().Unix())
}
if article.Type == models.ArticleRecord {
article.Coaches = []string{user.Id}
}
if article.Type == models.ArticleCoach {
if parent.Author != user.Id &&
user.Actor != models.ActorCoach && user.Actor != models.ActorAdmin {
writeResponse(request.RequestURI, resp, nil,
errors.NewError(errors.AccessError))
return
}
if err := article.Save(); err != nil {
log.Println(err)
writeResponse(request.RequestURI, resp, nil, err)
return
}
// ws push
event := &models.Event{
Type: models.EventArticle,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventCoach,
Id: parent.Id.Hex(),
From: user.Id,
//To: parent.Author,
Body: []models.MsgBody{
{Type: "total_count", Content: strconv.Itoa(parent.CoachReviewCount + 1)},
{Type: "image", Content: user.Profile},
},
},
}
for _, coach := range parent.Coaches {
if coach == user.Id {
continue
}
event.Data.To = coach
event.Save()
redis.PubMsg(models.EventArticle, coach, event.Bytes())
}
respData := map[string]interface{}{
"ExpEffect": Awards{},
}
writeResponse(request.RequestURI, resp, respData, nil)
return
}
if err := article.Save(); err != nil {
//.........這裏部分代碼省略.........
示例10: txHandler
//.........這裏部分代碼省略.........
if form.Value > amount {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError, "餘額不足"))
return
}
article := &models.Article{}
if strings.ToLower(form.Type) == "reward" && len(form.Id) > 0 {
if b, e := article.FindById(form.Id); !b {
err := errors.NewError(errors.NotExistsError, "文章不存在!")
if e != nil {
err = errors.NewError(errors.DbError)
}
writeResponse(r.RequestURI, w, nil, err)
return
}
}
changeAddr := form.FromAddr
if len(changeAddr) == 0 {
changeAddr = wal.Keys[0].PubKey
}
rawtx, err := CreateRawTx2(outputs, amount, form.Value, form.ToAddr, changeAddr)
if err != nil {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError))
return
}
txid, err := sendRawTx(rawtx)
if err != nil {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError))
return
}
redis.Transaction(user.Id, receiver.Id, form.Value)
// ws push
event := &models.Event{
Type: models.EventWallet,
Time: time.Now().Unix(),
}
//log.Println("tx type:", strings.ToLower(form.Type))
switch strings.ToLower(form.Type) {
case "reward":
article.Reward(user.Id, form.Value)
event.Data = models.EventData{
Type: models.EventReward,
Id: article.Id.Hex(),
From: user.Id,
To: receiver.Id,
Body: []models.MsgBody{
{Type: "nikename", Content: user.Nickname},
{Type: "image", Content: article.Image},
{Type: "total_count", Content: strconv.FormatInt(article.TotalReward, 10)},
//{Type: "new_count", Content: strconv.Itoa(models.EventCount(models.EventReward, article.Id.Hex()) + 1)},
},
}
default:
event.Data = models.EventData{
Type: models.EventTx,
Id: user.Id + "-" + receiver.Id,
From: user.Id,
To: receiver.Id,
Body: []models.MsgBody{
{Type: "nikename", Content: user.Nickname},
{Type: "image", Content: user.Profile},
{Type: "total_count", Content: strconv.FormatInt(form.Value, 10)},
},
}
}
if user.Id != receiver.Id {
/*
if err := event.Save(); err == nil {
redis.IncrEventCount(receiver.Id, event.Data.Type, 1)
}
*/
event.Save()
event.Data.Body = append(event.Data.Body,
models.MsgBody{Type: "new_count",
Content: strconv.Itoa(models.EventCount(event.Data.Type, event.Data.Id, event.Data.To))})
redis.PubMsg("wallet", receiver.Id, event.Bytes())
}
if receiver.Push {
msg := user.Nickname + "通過轉帳發送給你" +
strconv.FormatFloat(float64(form.Value)/float64(models.Satoshi), 'f', 8, 64) + "個貝幣"
if event.Data.Type == models.EventReward {
msg = user.Nickname + "給你的文章打賞了" +
strconv.FormatFloat(float64(form.Value)/float64(models.Satoshi), 'f', 8, 64) + "個貝幣"
}
go sendApn(client, msg, receiver.EventCount("", ""), receiver.Devs...)
}
writeResponse(r.RequestURI, w, map[string]string{"txid": txid}, nil)
}
示例11: 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":
//.........這裏部分代碼省略.........
示例12: taskAuthFunc
func taskAuthFunc(userid string, auth *taskAuth, redis *models.RedisLogger) error {
user := &models.Account{}
user.FindByUserid(auth.Userid)
record := &models.Record{Uid: user.Id, Task: auth.Id}
record.FindByTask(auth.Id)
awards := controllers.Awards{}
parent := &models.Article{}
parent.FindByRecord(record.Id.Hex())
if len(parent.Id) > 0 && len(auth.Reason) > 0 {
review := &models.Article{
Parent: parent.Id.Hex(),
Author: userid,
Title: auth.Reason,
Type: models.ArticleCoach,
Contents: []models.Segment{{ContentType: "TEXT", ContentText: auth.Reason}},
PubTime: time.Now(),
}
review.Save()
}
if auth.Pass {
level := user.Level()
awards = controllers.Awards{
Physical: 3 + level,
Wealth: 3 * models.Satoshi,
Score: 3 + level,
}
awards.Level = models.Score2Level(user.Props.Score+awards.Score) - level
controllers.GiveAwards(user, awards, redis)
if record.Sport != nil {
redis.UpdateRecLB(user.Id, record.Sport.Distance, int(record.Sport.Duration))
}
record.SetStatus(models.StatusFinish, auth.Reason, awards.Wealth)
if auth.Id < 1000 {
user.UpdateTask(int(auth.Id), models.StatusFinish)
}
} else {
record.SetStatus(models.StatusUnFinish, auth.Reason, 0)
if auth.Id < 1000 {
user.UpdateTask(int(auth.Id), models.StatusUnFinish)
}
parent.SetPrivilege(models.PrivPrivate)
}
// ws push
event := &models.Event{
Type: models.EventNotice,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventTaskDone,
To: user.Id,
Body: []models.MsgBody{
{Type: "physique_value", Content: strconv.FormatInt(awards.Physical, 10)},
{Type: "coin_value", Content: strconv.FormatInt(awards.Wealth, 10)},
},
},
}
if auth.Id < 1000 {
event.Data.Body = append(event.Data.Body, models.MsgBody{Type: "task_id", Content: strconv.Itoa(int(auth.Id))})
}
if !auth.Pass {
event.Data.Type = models.EventTaskFailure
}
redis.PubMsg(event.Type, event.Data.To, event.Bytes())
event.Save()
event = &models.Event{
Type: models.EventArticle,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventCoachPass,
Id: parent.Id.Hex(),
From: userid,
To: parent.Author,
Body: []models.MsgBody{
{Type: "total_count", Content: strconv.Itoa(parent.CoachReviewCount + 1)},
{Type: "image", Content: ""},
},
},
}
if !auth.Pass {
event.Data.Type = models.EventCoachNPass
}
event.Save()
redis.PubMsg(event.Type, event.Data.To, event.Bytes())
return nil
}