本文整理匯總了Golang中github.com/ginuerzh/sports/models.Account.Recommend方法的典型用法代碼示例。如果您正苦於以下問題:Golang Account.Recommend方法的具體用法?Golang Account.Recommend怎麽用?Golang Account.Recommend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.Account
的用法示例。
在下文中一共展示了Account.Recommend方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: articleListHandler
func articleListHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
var articles []models.Article
var err error
form := p.(articleListForm)
if len(form.Tag) > 0 {
_, articles, err = models.GetArticles(form.Tag, &form.Paging, true)
} else if form.Circle {
followings := redis.Friends(models.RelFollowing, user.Id)
followings = append(followings, user.Id) // self included
_, articles, err = models.GetFollowingsArticles(followings, &form.Paging)
} else {
excludes := redis.Friends(models.RelFollowing, user.Id)
excludes = append(excludes, redis.Friends(models.RelBlacklist, user.Id)...)
excludes = append(excludes, user.Id)
recommends, _ := user.Recommend(excludes)
ids := []string{}
for i, _ := range recommends {
ids = append(ids, recommends[i].Id)
}
_, articles, err = models.GetRecommendArticles(ids, &form.Paging)
}
jsonStructs := make([]*articleJsonStruct, len(articles))
for i, _ := range articles {
u := &models.Account{}
u.FindByUserid(articles[i].Author)
author := convertUser(u, redis)
jsonStructs[i] = convertArticle(user, &articles[i], author)
}
respData := make(map[string]interface{})
respData["page_frist_id"] = form.Paging.First
respData["page_last_id"] = form.Paging.Last
//respData["page_item_count"] = total
respData["articles_without_content"] = jsonStructs
writeResponse(request.RequestURI, resp, respData, err)
}