本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.Relationship方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.Relationship方法的具體用法?Golang RedisLogger.Relationship怎麽用?Golang RedisLogger.Relationship使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.RedisLogger
的用法示例。
在下文中一共展示了RedisLogger.Relationship方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: userInfoHandler
func userInfoHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, p Parameter) {
user := &models.Account{}
form := p.(getInfoForm)
if find, err := user.FindByUserid(form.Userid); !find {
if err == nil {
err = errors.NewError(errors.NotExistsError)
}
writeResponse(request.RequestURI, resp, nil, err)
return
}
info := convertUser(user, redis)
//info.Pet = userPet(info.Props.Level)
info.ScoreRank, _ = user.PropIndex("score", user.Props.Score)
if uid := redis.OnlineUser(p.TokenId()); len(uid) > 0 {
relation := redis.Relationship(uid, user.Id)
switch relation {
case models.RelFriend:
info.Relation = "FRIENDS"
case models.RelFollowing:
info.Relation = "ATTENTION"
case models.RelFollower:
info.Relation = "FANS"
case models.RelBlacklist:
info.Relation = "DEFRIEND"
}
}
writeResponse(request.RequestURI, resp, info, 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: recommendHandler
func recommendHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(recommendForm)
excludes := redis.Friends(models.RelFollowing, user.Id)
excludes = append(excludes, redis.Friends(models.RelBlacklist, user.Id)...)
users, _ := user.Recommend(excludes)
var list []*leaderboardResp
for i, _ := range users {
if users[i].Id == user.Id {
continue
}
rel := redis.Relationship(user.Id, users[i].Id)
if rel == models.RelFollowing || rel == models.RelFriend {
continue
}
lb := &leaderboardResp{
Userid: users[i].Id,
Score: users[i].Props.Score,
Level: users[i].Level(),
Profile: users[i].Profile,
Nickname: users[i].Nickname,
Gender: users[i].Gender,
LastLog: users[i].LastLogin.Unix(),
Birth: users[i].Birth,
Location: users[i].Loc,
Addr: users[i].LocAddr,
Phone: users[i].Phone,
Actor: users[i].Actor,
}
lb.Distance, _ = redis.RecStats(users[i].Id)
lb.Status = users[i].LatestArticle().Title
list = append(list, lb)
}
respData := map[string]interface{}{
"members_list": list,
"page_frist_id": form.Paging.First,
"page_last_id": form.Paging.Last,
}
writeResponse(r.RequestURI, w, respData, nil)
}
示例4: articleInfoHandler
func articleInfoHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(articleInfoForm)
article := &models.Article{}
if find, err := article.FindById(form.Id); !find {
if err == nil {
err = errors.NewError(errors.NotExistsError)
}
writeResponse(request.RequestURI, resp, nil, err)
return
}
event := &models.Event{}
//event.Data.Type = models.EventThumb
event.Data.Id = article.Id.Hex()
event.Data.To = user.Id
event.Clear() // clear all events about this article
u := &models.Account{}
u.FindByUserid(article.Author)
author := convertUser(u, redis)
jsonStruct := convertArticle(user, article, author)
jsonStruct.Relation = redis.Relationship(user.Id, article.Author)
switch jsonStruct.Relation {
case models.RelFriend:
jsonStruct.Relation = "FRIENDS"
case models.RelFollowing:
jsonStruct.Relation = "ATTENTION"
case models.RelFollower:
jsonStruct.Relation = "FANS"
case models.RelBlacklist:
jsonStruct.Relation = "DEFRIEND"
}
writeResponse(request.RequestURI, resp, jsonStruct, nil)
}
示例5: 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())
}
示例6: 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 {
//.........這裏部分代碼省略.........
示例7: txHandler
func txHandler(r *http.Request, w http.ResponseWriter,
client *ApnClient, redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(txForm)
if form.FromAddr == form.ToAddr {
writeResponse(r.RequestURI, w, map[string]string{"txid": ""}, nil)
return
}
if form.Value <= 0 {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError, "無效的金額"))
return
}
receiver := &models.Account{}
if find, err := receiver.FindByWalletAddr(form.ToAddr); !find {
e := errors.NewError(errors.NotFoundError, "無效的收款地址")
if err != nil {
e = errors.NewError(errors.DbError, "無效的錢包地址")
}
writeResponse(r.RequestURI, w, nil, e)
return
}
if redis.Relationship(receiver.Id, user.Id) == models.RelBlacklist {
writeResponse(r.RequestURI, w, nil,
errors.NewError(errors.AccessError, "對方屏蔽了你!"))
return
}
wal, err := getWallet(user.Wallet.Id, user.Wallet.Key)
if err != nil {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, "獲取錢包失敗"))
return
}
outputs, amount, err := getUnspent(form.FromAddr, wal.Keys, form.Value)
if err != nil {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, "獲取賬戶信息失敗"))
return
}
//log.Println("amount:", amount, "value:", form.Value)
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)},
//.........這裏部分代碼省略.........