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


Golang Storage.TagByName方法代碼示例

本文整理匯總了Golang中tmsu/storage.Storage.TagByName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Storage.TagByName方法的具體用法?Golang Storage.TagByName怎麽用?Golang Storage.TagByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tmsu/storage.Storage的用法示例。


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

示例1: listValuesForTag

func listValuesForTag(store *storage.Storage, tagName string, showCount, onePerLine bool) error {
	tag, err := store.TagByName(tagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err)
	}
	if tag == nil {
		return fmt.Errorf("no such tag, '%v'.", tagName)
	}

	log.Infof(2, "retrieving values for tag '%v'.", tagName)

	values, err := store.ValuesByTag(tag.Id)
	if err != nil {
		return fmt.Errorf("could not retrieve values for tag '%v': %v", tagName, err)
	}

	if showCount {
		fmt.Println(len(values))
	} else {
		if onePerLine {
			for _, value := range values {
				fmt.Println(value.Name)
			}
		} else {
			valueNames := make([]string, len(values))
			for index, value := range values {
				valueNames[index] = value.Name
			}

			format.Columns(valueNames, terminalWidth())
		}
	}

	return nil
}
開發者ID:Konubinix,項目名稱:tmsu,代碼行數:35,代碼來源:values.go

示例2: getOrCreateTag

func getOrCreateTag(store *storage.Storage, tagName string) (*entities.Tag, error) {
	tag, err := store.TagByName(tagName)
	if err != nil {
		return nil, fmt.Errorf("could not look up tag '%v': %v", tagName, err)
	}

	if tag == nil {
		tag, err = store.AddTag(tagName)
		if err != nil {
			return nil, fmt.Errorf("could not create tag '%v': %v", tagName, err)
		}

		log.Warnf("New tag '%v'.", tagName)
	}

	return tag, nil
}
開發者ID:Konubinix,項目名稱:tmsu,代碼行數:17,代碼來源:tag.go

示例3: listValuesForTags

func listValuesForTags(store *storage.Storage, tagNames []string, showCount, onePerLine bool) error {
	wereErrors := false
	for _, tagName := range tagNames {
		tag, err := store.TagByName(tagName)
		if err != nil {
			return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err)
		}
		if tag == nil {
			log.Warnf("no such tag, '%v'.", tagName)
			wereErrors = true
			continue
		}

		log.Infof(2, "retrieving values for tag '%v'.", tagName)

		values, err := store.ValuesByTag(tag.Id)
		if err != nil {
			return fmt.Errorf("could not retrieve values for tag '%v': %v", tagName, err)
		}

		if showCount {
			fmt.Printf("%v: %v\n", tagName, len(values))
		} else {
			if onePerLine {
				fmt.Println(tagName)
				for _, value := range values {
					fmt.Println(value.Name)
				}
				fmt.Println()
			} else {
				valueNames := make([]string, len(values))
				for index, value := range values {
					valueNames[index] = value.Name
				}

				fmt.Printf("%v: %v\n", tagName, strings.Join(valueNames, " "))
			}
		}
	}

	if wereErrors {
		return blankError
	}

	return nil
}
開發者ID:Konubinix,項目名稱:tmsu,代碼行數:46,代碼來源:values.go

示例4: deleteTag

func (command DeleteCommand) deleteTag(store *storage.Storage, tagName string) error {
	tag, err := store.TagByName(tagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err)
	}
	if tag == nil {
		return fmt.Errorf("no such tag '%v'.", tagName)
	}

	if command.verbose {
		log.Infof("finding files tagged '%v'.", tagName)
	}

	fileTags, err := store.FileTagsByTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not retrieve taggings for tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("removing applications of tag '%v'.", tagName)
	}

	err = store.RemoveFileTagsByTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not remove taggings for tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("removing tags implications involving tag '%v'.", tagName)
	}

	err = store.RemoveImplicationsForTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not remove tag implications involving tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("deleting tag '%v'.", tagName)
	}

	err = store.DeleteTag(tag.Id)
	if err != nil {
		return fmt.Errorf("could not delete tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("identifying files left untagged as a result of tag deletion.")
	}

	removedFileCount := 0
	for _, fileTag := range fileTags {
		count, err := store.FileTagCountByFileId(fileTag.FileId)
		if err != nil {
			return fmt.Errorf("could not retrieve taggings count for file #%v: %v", fileTag.FileId, err)
		}
		if count == 0 {
			err := store.RemoveFile(fileTag.FileId)
			if err != nil {
				return fmt.Errorf("could not remove file #%v: %v", fileTag.FileId, err)
			}

			removedFileCount += 1
		}
	}

	if command.verbose {
		log.Infof("removed %v untagged files.", removedFileCount)
	}

	return nil
}
開發者ID:kelvinhammond,項目名稱:tmsu,代碼行數:71,代碼來源:delete.go


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