本文整理汇总了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)
}