當前位置: 首頁>>代碼示例>>Golang>>正文


Golang util.Join函數代碼示例

本文整理匯總了Golang中util.Join函數的典型用法代碼示例。如果您正苦於以下問題:Golang Join函數的具體用法?Golang Join怎麽用?Golang Join使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Join函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: FindUsers

func FindUsers() (map[int]*model.User, error) {
	userList, err := model.NewUser().FindAll()
	if err != nil {
		logger.Errorln("user service FindUsers Error:", err)
		return nil, err
	}
	userCount := len(userList)
	userMap := make(map[int]*model.User, userCount)
	uids := make([]int, userCount)
	for i, user := range userList {
		userMap[user.Uid] = user
		uids[i] = user.Uid
	}
	// 獲得角色信息
	userRoleList, err := model.NewUserRole().Where("uid in (" + util.Join(uids, ",") + ")").FindAll()
	if err != nil {
		logger.Errorln("user service FindUsers Error:", err)
		return nil, err
	}
	for _, userRole := range userRoleList {
		user := userMap[userRole.Uid]
		if len(user.Roleids) == 0 {
			user.Roleids = []int{userRole.Roleid}
			user.Rolenames = []string{model.AllRole[userRole.Roleid].Name}
		} else {
			user.Roleids = append(user.Roleids, userRole.Roleid)
			user.Rolenames = append(user.Rolenames, model.AllRole[userRole.Roleid].Name)
		}
	}
	return userMap, nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:31,代碼來源:user.go

示例2: FindTopicsByTids

// 獲取多個帖子詳細信息
func FindTopicsByTids(tids []int) []*model.Topic {
	inTids := util.Join(tids, ",")
	topics, err := model.NewTopic().Where("tid in(" + inTids + ")").FindAll()
	if err != nil {
		logger.Errorln("topic service FindRecentReplies error:", err)
		return nil
	}
	return topics
}
開發者ID:sndnvaps,項目名稱:studygolang,代碼行數:10,代碼來源:topic.go

示例3: FindWikisByIds

// 獲取多個wiki頁麵詳細信息
func FindWikisByIds(ids []int) []*model.Wiki {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	wikis, err := model.NewWiki().Where("id in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("wiki service FindWikisByIds error:", err)
		return nil
	}
	return wikis
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:13,代碼來源:wiki.go

示例4: FindArticlesByIds

// 獲取多個文章詳細信息
func FindArticlesByIds(ids []int) []*model.Article {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	articles, err := model.NewArticle().Where("id in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("article service FindArticlesByIds error:", err)
		return nil
	}
	return articles
}
開發者ID:lewgun,項目名稱:studygolang,代碼行數:13,代碼來源:article.go

示例5: FindResourcesByIds

// 獲取多個資源詳細信息
func FindResourcesByIds(ids []int) []*model.Resource {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	resources, err := model.NewResource().Where("id in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("resource service FindResourcesByIds error:", err)
		return nil
	}
	return resources
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:13,代碼來源:resource.go

示例6: FindProjectsByIds

// 獲取多個項目詳細信息
func FindProjectsByIds(ids []int) []*model.OpenProject {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	projects, err := model.NewOpenProject().Where("id in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("project service FindProjectsByIds error:", err)
		return nil
	}
	return projects
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:13,代碼來源:project.go

示例7: FindCommentsByIds

// 獲取多個評論信息
func FindCommentsByIds(cids []int) []*model.Comment {
	if len(cids) == 0 {
		return nil
	}
	inCids := util.Join(cids, ",")
	comments, err := model.NewComment().Where("cid in(" + inCids + ")").FindAll()
	if err != nil {
		logger.Errorln("comment service FindCommentsByIds error:", err)
		return nil
	}
	return comments
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:13,代碼來源:comment.go

示例8: FindTopicsByIds

// 獲取多個主題詳細信息
func FindTopicsByIds(ids []int) []*model.Topic {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	topics, err := model.NewTopic().Where("tid in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("topic service FindTopicsByIds error:", err)
		return nil
	}
	return topics
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:13,代碼來源:topic.go

示例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
}
開發者ID:sndnvaps,項目名稱:studygolang,代碼行數:15,代碼來源:user.go

示例10: FindResourcesByCatid

// 獲得某個分類的資源列表
func FindResourcesByCatid(catid string) []map[string]interface{} {
	resourceList, err := model.NewResource().Where("catid=" + catid).Order("mtime DESC").FindAll()
	if err != nil {
		logger.Errorln("resource service FindResourcesByCatid error:", err)
		return nil
	}
	count := len(resourceList)
	ids := make([]int, count)
	uids := make(map[int]int)
	for i, resource := range resourceList {
		ids[i] = resource.Id
		uids[resource.Uid] = resource.Uid
	}

	// 獲取擴展信息(計數)
	resourceExList, err := model.NewResourceEx().Where("id in(" + util.Join(ids, ",") + ")").FindAll()
	if err != nil {
		logger.Errorln("resource service FindResourcesByCatid Error:", err)
		return nil
	}
	resourceExMap := make(map[int]*model.ResourceEx, len(resourceExList))
	for _, resourceEx := range resourceExList {
		resourceExMap[resourceEx.Id] = resourceEx
	}

	userMap := getUserInfos(uids)

	resources := make([]map[string]interface{}, count)
	for i, resource := range resourceList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, resource)
		util.Struct2Map(tmpMap, resourceExMap[resource.Id])
		tmpMap["user"] = userMap[resource.Uid]
		// 鏈接的host
		if resource.Form == model.LinkForm {
			urlObj, err := url.Parse(resource.Url)
			if err == nil {
				tmpMap["host"] = urlObj.Host
			}
		} else {
			tmpMap["url"] = "/resources/" + strconv.Itoa(resource.Id)
		}
		resources[i] = tmpMap
	}
	return resources
}
開發者ID:Neeke,項目名稱:studygolang,代碼行數:47,代碼來源:resource.go

示例11: MarkHasRead

// 標記消息已讀
func MarkHasRead(ids []int, isSysMsg bool, uid int) bool {
	if len(ids) == 0 {
		return true
	}
	condition := "id=" + strconv.Itoa(ids[0])
	if len(ids) > 1 {
		condition = "id in(" + util.Join(ids, ",") + ")"
	}
	var err error
	if isSysMsg {
		err = model.NewSystemMessage().Set("hasread=" + model.HasRead).Where(condition).Update()
	} else {
		err = model.NewMessage().Set("hasread=" + model.HasRead).Where(condition).Update()
	}
	if err != nil {
		logger.Errorln("message service MarkHasRead Error:", err)
		return false
	}

	return true
}
開發者ID:philsong,項目名稱:studygolang,代碼行數:22,代碼來源:message.go

示例12: FindTopicsByWhere

func FindTopicsByWhere(where, order, limit string) (topics []map[string]interface{}, total int) {
	topicObj := model.NewTopic()
	if where != "" {
		topicObj.Where(where)
	}
	if order != "" {
		topicObj.Order(order)
	}
	if limit != "" {
		topicObj.Limit(limit)
	}
	topicList, err := topicObj.FindAll()
	if err != nil {
		logger.Errorln("topic service topicObj.FindAll Error:", err)
		return
	}
	// 獲得總帖子數
	total, err = topicObj.Count()
	if err != nil {
		logger.Errorln("topic service topicObj.Count Error:", err)
		return
	}
	count := len(topicList)
	tids := make([]int, count)
	uids := make(map[int]int)
	nids := make([]int, count)
	for i, topic := range topicList {
		tids[i] = topic.Tid
		uids[topic.Uid] = topic.Uid
		if topic.Lastreplyuid != 0 {
			uids[topic.Lastreplyuid] = topic.Lastreplyuid
		}
		nids[i] = topic.Nid
	}

	// 獲取擴展信息(計數)
	topicExList, err := model.NewTopicEx().Where("tid in(" + util.Join(tids, ",") + ")").FindAll()
	if err != nil {
		logger.Errorln("topic service NewTopicEx FindAll Error:", err)
		return
	}
	topicExMap := make(map[int]*model.TopicEx, len(topicExList))
	for _, topicEx := range topicExList {
		topicExMap[topicEx.Tid] = topicEx
	}

	userMap := getUserInfos(uids)

	// 獲取節點信息
	nodes := model.GetNodesName(nids)

	topics = make([]map[string]interface{}, count)
	for i, topic := range topicList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, topic)
		util.Struct2Map(tmpMap, topicExMap[topic.Tid])
		tmpMap["user"] = userMap[topic.Uid]
		// 有人回複
		if tmpMap["lastreplyuid"].(int) != 0 {
			tmpMap["lastreplyusername"] = userMap[tmpMap["lastreplyuid"].(int)].Username
		}
		tmpMap["node"] = nodes[tmpMap["nid"].(int)]
		topics[i] = tmpMap
	}
	return
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:66,代碼來源:topic.go

示例13: FindResourcesByCatid

// 獲得某個分類的資源列表
// page 當前第幾頁
func FindResourcesByCatid(catid string, page int) (resources []map[string]interface{}, total int) {
	var offset = 0
	if page > 1 {
		offset = (page - 1) * PAGE_NUM
	}

	resourceObj := model.NewResource()
	limit := strconv.Itoa(offset) + "," + strconv.Itoa(PAGE_NUM)
	resourceList, err := resourceObj.Where("catid=?", catid).Order("mtime DESC").Limit(limit).FindAll()
	if err != nil {
		logger.Errorln("resource service FindResourcesByCatid error:", err)
		return
	}

	// 獲得該類別總資源數
	total, err = resourceObj.Count()
	if err != nil {
		logger.Errorln("resource service resourceObj.Count Error:", err)
		return
	}

	count := len(resourceList)
	ids := make([]int, count)
	uids := make([]int, count)
	for i, resource := range resourceList {
		ids[i] = resource.Id
		uids[i] = resource.Uid
	}

	// 獲取擴展信息(計數)
	resourceExList, err := model.NewResourceEx().Where("id in(" + util.Join(ids, ",") + ")").FindAll()
	if err != nil {
		logger.Errorln("resource service FindResourcesByCatid Error:", err)
		return
	}
	resourceExMap := make(map[int]*model.ResourceEx, len(resourceExList))
	for _, resourceEx := range resourceExList {
		resourceExMap[resourceEx.Id] = resourceEx
	}

	userMap := GetUserInfos(uids)

	resources = make([]map[string]interface{}, count)
	for i, resource := range resourceList {
		tmpMap := make(map[string]interface{})
		util.Struct2Map(tmpMap, resource)
		util.Struct2Map(tmpMap, resourceExMap[resource.Id])
		tmpMap["user"] = userMap[resource.Uid]
		// 鏈接的host
		if resource.Form == model.LinkForm {
			urlObj, err := url.Parse(resource.Url)
			if err == nil {
				tmpMap["host"] = urlObj.Host
			}
		} else {
			tmpMap["url"] = "/resources/" + strconv.Itoa(resource.Id)
		}
		resources[i] = tmpMap
	}
	return
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:63,代碼來源:resource.go


注:本文中的util.Join函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。