本文整理匯總了Golang中util.MapIntKeys函數的典型用法代碼示例。如果您正苦於以下問題:Golang MapIntKeys函數的具體用法?Golang MapIntKeys怎麽用?Golang MapIntKeys使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MapIntKeys函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FindRecentReplies
// 獲得回複對應的主貼信息
func FindRecentReplies(comments []*model.Comment) []map[string]interface{} {
if len(comments) == 0 {
return nil
}
count := len(comments)
commentMap := make(map[int]*model.Comment, count)
tidMap := make(map[int]int, count)
for _, comment := range comments {
commentMap[comment.Objid] = comment
tidMap[comment.Objid] = comment.Objid
}
tids := util.MapIntKeys(tidMap)
topics := FindTopicsByTids(tids)
if len(topics) == 0 {
return nil
}
result := make([]map[string]interface{}, len(topics))
for i, topic := range topics {
oneReply := make(map[string]interface{})
oneReply["tid"] = topic.Tid
oneReply["title"] = topic.Title
oneReply["cmt_content"] = decodeCmtContent(commentMap[topic.Tid])
oneReply["replytime"] = commentMap[topic.Tid].Ctime
result[i] = oneReply
}
return result
}
示例2: FindHotTopics
// 獲得回複最多的10條帖子(TODO:避免一直顯示相同的)
func FindHotTopics() []map[string]interface{} {
topicExList, err := model.NewTopicEx().Order("reply DESC").Limit("0,10").FindAll()
if err != nil {
logger.Errorln("topic service FindHotReplies error:", err)
return nil
}
tidMap := make(map[int]int, len(topicExList))
topicExMap := make(map[int]*model.TopicEx, len(topicExList))
for _, topicEx := range topicExList {
tidMap[topicEx.Tid] = topicEx.Tid
topicExMap[topicEx.Tid] = topicEx
}
tids := util.MapIntKeys(tidMap)
topics := FindTopicsByTids(tids)
if topics == nil {
return nil
}
uidMap := make(map[int]int, len(topics))
for _, topic := range topics {
uidMap[topic.Uid] = topic.Uid
}
userMap := getUserInfos(uidMap)
result := make([]map[string]interface{}, len(topics))
for i, topic := range topics {
oneTopic := make(map[string]interface{})
util.Struct2Map(oneTopic, topic)
util.Struct2Map(oneTopic, topicExMap[topic.Tid])
oneTopic["user"] = userMap[topic.Uid]
result[i] = oneTopic
}
return result
}
示例3: getWikis
// 提供給其他service調用(包內)
func getWikis(ids map[int]int) map[int]*model.Wiki {
wikis := FindWikisByIds(util.MapIntKeys(ids))
wikiMap := make(map[int]*model.Wiki, len(wikis))
for _, wiki := range wikis {
wikiMap[wiki.Id] = wiki
}
return wikiMap
}
示例4: getTopics
// 提供給其他service調用(包內)
func getTopics(tids map[int]int) map[int]*model.Topic {
topics := FindTopicsByTids(util.MapIntKeys(tids))
topicMap := make(map[int]*model.Topic, len(topics))
for _, topic := range topics {
topicMap[topic.Tid] = topic
}
return topicMap
}
示例5: getArticles
// 提供給其他service調用(包內)
func getArticles(ids map[int]int) map[int]*model.Article {
articles := FindArticlesByIds(util.MapIntKeys(ids))
articleMap := make(map[int]*model.Article, len(articles))
for _, article := range articles {
articleMap[article.Id] = article
}
return articleMap
}
示例6: getResources
// 提供給其他service調用(包內)
func getResources(ids map[int]int) map[int]*model.Resource {
resources := FindResourcesByIds(util.MapIntKeys(ids))
resourceMap := make(map[int]*model.Resource, len(resources))
for _, resource := range resources {
resourceMap[resource.Id] = resource
}
return resourceMap
}
示例7: getProjects
// 提供給其他service調用(包內)
func getProjects(ids map[int]int) map[int]*model.OpenProject {
projects := FindProjectsByIds(util.MapIntKeys(ids))
projectMap := make(map[int]*model.OpenProject, len(projects))
for _, project := range projects {
projectMap[project.Id] = project
}
return projectMap
}
示例8: getComments
// 提供給其他service調用(包內)
func getComments(cids map[int]int) map[int]*model.Comment {
comments := FindCommentsByIds(util.MapIntKeys(cids))
commentMap := make(map[int]*model.Comment, len(comments))
for _, comment := range comments {
commentMap[comment.Cid] = comment
}
return commentMap
}
示例9: getUserInfos
// 獲取用戶信息
func getUserInfos(uids map[int]int) map[int]*model.User {
// 獲取用戶信息
inUids := util.Join(util.MapIntKeys(uids), ",")
users, err := model.NewUser().Where("uid in(" + inUids + ")").FindAll()
if err != nil {
logger.Errorln("user service getUserInfos Error:", err)
return map[int]*model.User{}
}
userMap := make(map[int]*model.User, len(users))
for _, user := range users {
userMap[user.Uid] = user
}
return userMap
}
示例10: FillCommentObjs
// 填充評論對應的主體信息
func FillCommentObjs(comments []*model.Comment, cmtObj CommentObjecter) {
if len(comments) == 0 {
return
}
count := len(comments)
commentMap := make(map[int][]*model.Comment, count)
idMap := make(map[int]int, count)
for _, comment := range comments {
if _, ok := commentMap[comment.Objid]; !ok {
commentMap[comment.Objid] = make([]*model.Comment, 0, count)
}
commentMap[comment.Objid] = append(commentMap[comment.Objid], comment)
idMap[comment.Objid] = 1
}
ids := util.MapIntKeys(idMap)
cmtObj.SetObjinfo(ids, commentMap)
}