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


Golang util.MapKeys函數代碼示例

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


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

示例1: Find

// Find 查找單條數據
// colFieldMap 數據庫表中列對應go中對象的字段
func (this *Dao) Find(colFieldMap map[string]interface{}, selectCol ...string) error {
	colNum := len(selectCol)
	if colNum == 0 || (colNum == 1 && selectCol[0] == "*") {
		selectCol = util.MapKeys(colFieldMap)
	}
	sort.Sort(sort.StringSlice(selectCol))
	this.selectCols = "`" + strings.Join(selectCol, "`,`") + "`"
	strSql := util.SelectSql(this)
	logger.Debugln("Find sql:", strSql)
	err := this.Open()
	if err != nil {
		return err
	}
	defer this.Close()
	row := this.QueryRow(strSql, this.whereVal...)
	scanInterface := make([]interface{}, 0, colNum)
	for _, column := range selectCol {
		scanInterface = append(scanInterface, colFieldMap[column])
	}
	err = row.Scan(scanInterface...)
	if err == sql.ErrNoRows {
		logger.Infoln("Find", strSql, ":no result ret")
		return nil
	}
	return err
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:28,代碼來源:dao.go

示例2: FindAll

func (this *TopicNode) FindAll(selectCol ...string) ([]*TopicNode, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	nodeList := make([]*TopicNode, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		node := NewTopicNode()
		colFieldMap := node.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("TopicNode FindAll Scan Error:", err)
			continue
		}
		nodeList = append(nodeList, node)
	}
	return nodeList, nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:28,代碼來源:topic.go

示例3: FindAll

func (this *MorningReading) FindAll(selectCol ...string) ([]*MorningReading, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	readingList := make([]*MorningReading, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		reading := NewMorningReading()
		err = this.Scan(rows, colNum, reading.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("MorningReading FindAll Scan Error:", err)
			continue
		}
		reading.Rdate = reading.Ctime[:10]
		if reading.Moreurls != "" {
			reading.Urls = strings.Split(reading.Moreurls, ",")
		}
		readingList = append(readingList, reading)
	}
	return readingList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:27,代碼來源:reading.go

示例4: FindAll

func (this *UserRole) FindAll(selectCol ...string) ([]*UserRole, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		logger.Errorln("[UserRole.FindAll] error:", err)
		return nil, err
	}
	// TODO:
	userRoleList := make([]*UserRole, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		userRole := NewUserRole()
		colFieldMap := userRole.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("[UserRole.FindAll Rows] error:", err)
		}
		userRoleList = append(userRoleList, userRole)
	}
	return userRoleList, nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:27,代碼來源:user.go

示例5: FindAll

func (this *Comment) FindAll(selectCol ...string) ([]*Comment, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	commentList := make([]*Comment, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		comment := NewComment()
		colFieldMap := comment.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("Comment FindAll Scan Error:", err)
			continue
		}
		commentList = append(commentList, comment)
	}
	return commentList, nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:27,代碼來源:comment.go

示例6: FindAll

func (this *Comment) FindAll(selectCol ...string) ([]*Comment, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	commentList := make([]*Comment, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		comment := NewComment()
		err = this.Scan(rows, colNum, comment.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Comment FindAll Scan Error:", err)
			continue
		}
		commentList = append(commentList, comment)
	}
	return commentList, nil
}
開發者ID:jackyxie,項目名稱:btcrobot,代碼行數:22,代碼來源:comment.go

示例7: FindAll

func (this *Message) FindAll(selectCol ...string) ([]*Message, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	messageList := make([]*Message, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		message := NewMessage()
		err = this.Scan(rows, colNum, message.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Message FindAll Scan Error:", err)
			continue
		}
		messageList = append(messageList, message)
	}
	return messageList, nil
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:22,代碼來源:message.go

示例8: FindAll

func (this *Like) FindAll(selectCol ...string) ([]*Like, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	likeList := make([]*Like, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		like := NewLike()
		err = this.Scan(rows, colNum, like.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Like FindAll Scan Error:", err)
			continue
		}
		likeList = append(likeList, like)
	}
	return likeList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:22,代碼來源:like.go

示例9: FindAll

func (this *TopicNode) FindAll(selectCol ...string) ([]*TopicNode, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	nodeList := make([]*TopicNode, 0, 10)
	//logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		node := NewTopicNode()
		err = this.Scan(rows, colNum, node.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("TopicNode FindAll Scan Error:", err)
			continue
		}
		nodeList = append(nodeList, node)
	}
	return nodeList, nil
}
開發者ID:xuzhiping7,項目名稱:studygolang,代碼行數:23,代碼來源:topic.go

示例10: FindAll

func (this *Favorite) FindAll(selectCol ...string) ([]*Favorite, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	favoriteList := make([]*Favorite, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		favorite := NewFavorite()
		err = this.Scan(rows, colNum, favorite.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Favorite FindAll Scan Error:", err)
			continue
		}
		favoriteList = append(favoriteList, favorite)
	}
	return favoriteList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:23,代碼來源:favorite.go

示例11: FindAll

func (this *RoleAuthority) FindAll(selectCol ...string) ([]*RoleAuthority, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	roleAuthList := make([]*RoleAuthority, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		roleAuth := NewRoleAuthority()
		err = this.Scan(rows, colNum, roleAuth.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("RoleAuthority FindAll Scan Error:", err)
			continue
		}
		roleAuthList = append(roleAuthList, roleAuth)
	}
	return roleAuthList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:23,代碼來源:role.go

示例12: FindAll

func (this *OpenProject) FindAll(selectCol ...string) ([]*OpenProject, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	projectList := make([]*OpenProject, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		project := NewOpenProject()
		err = this.Scan(rows, colNum, project.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("OpenProject FindAll Scan Error:", err)
			continue
		}
		projectList = append(projectList, project)
	}
	return projectList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:23,代碼來源:openproject.go

示例13: FindAll

func (this *UserRole) FindAll(selectCol ...string) ([]*UserRole, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		logger.Errorln("[UserRole.FindAll] error:", err)
		return nil, err
	}
	// TODO:
	userRoleList := make([]*UserRole, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		userRole := NewUserRole()
		err = this.Scan(rows, colNum, userRole.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("UserRole FindAll Scan Error:", err)
			continue
		}
		userRoleList = append(userRoleList, userRole)
	}
	return userRoleList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:23,代碼來源:user.go

示例14: FindAll

func (this *Wiki) FindAll(selectCol ...string) ([]*Wiki, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	wikiList := make([]*Wiki, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		wiki := NewWiki()
		err = this.Scan(rows, colNum, wiki.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Wiki FindAll Scan Error:", err)
			continue
		}
		wikiList = append(wikiList, wiki)
	}
	return wikiList, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:23,代碼來源:wiki.go

示例15: FindAll

func (this *Resource) FindAll(selectCol ...string) ([]*Resource, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	resourceList := make([]*Resource, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		resource := NewResource()
		err = this.Scan(rows, colNum, resource.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Resource FindAll Scan Error:", err)
			continue
		}
		resourceList = append(resourceList, resource)
	}
	return resourceList, nil
}
開發者ID:BillyMC,項目名稱:studygolang,代碼行數:23,代碼來源:resource.go


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