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


Golang Vault.AddItem方法代碼示例

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


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

示例1: importItems

func importItems(vault *onepass.Vault, path string) {
	items, err := onepass.ImportItems(path)
	if err != nil {
		fatalErr(err, "Unable to import items")
	}
	for _, importedItem := range items {
		item, err := vault.AddItem(importedItem.Title, importedItem.TypeName, importedItem.SecureContents)
		if err != nil {
			fatalErr(err, fmt.Sprintf("Unable to import item '%s'", importedItem.Title))
		}
		logItemAction("Imported item", item)
	}
}
開發者ID:gaku,項目名稱:1pass,代碼行數:13,代碼來源:client.go

示例2: addItem

func addItem(vault *onepass.Vault, title string, shortTypeName string) {
	itemContent := onepass.ItemContent{}
	var typeName string
	for typeKey, itemType := range onepass.ItemTypes {
		if itemType.ShortAlias == shortTypeName {
			itemContent = onepass.ItemContent{}
			typeName = typeKey
		}
	}
	if len(typeName) == 0 {
		fatalErr(fmt.Errorf("Unknown item type '%s'", shortTypeName), "")
	}

	template, ok := onepass.StandardTemplate(typeName)
	if !ok {
		fatalErr(fmt.Errorf("No template for item type '%s'", shortTypeName), "")
	}

	// read sections
	for _, sectionTemplate := range template.Sections {
		section := onepass.ItemSection{
			Name:   sectionTemplate.Name,
			Title:  sectionTemplate.Title,
			Fields: []onepass.ItemField{},
		}
		for _, fieldTemplate := range sectionTemplate.Fields {
			field := onepass.ItemField{
				Name:  fieldTemplate.Name,
				Title: fieldTemplate.Title,
				Kind:  fieldTemplate.Kind,
			}
			field.Value = readFieldValue(field)

			section.Fields = append(section.Fields, field)
		}
		itemContent.Sections = append(itemContent.Sections, section)
	}

	// read form fields
	for _, formFieldTemplate := range template.FormFields {
		field := onepass.WebFormField{
			Name:        formFieldTemplate.Name,
			Id:          formFieldTemplate.Id,
			Type:        formFieldTemplate.Type,
			Designation: formFieldTemplate.Designation,
		}
		field.Value = readFormFieldValue(field)

		itemContent.FormFields = append(itemContent.FormFields, field)
	}

	// read URLs
	for _, urlTemplate := range template.Urls {
		url := onepass.ItemUrl{
			Label: urlTemplate.Label,
		}
		url.Url = readLinePrompt("%s (URL)", url.Label)
		itemContent.Urls = append(itemContent.Urls, url)
	}

	// save item to vault
	item, err := vault.AddItem(title, typeName, itemContent)
	if err != nil {
		fatalErr(err, "Unable to add item")
	}
	logItemAction("Added new item", item)
}
開發者ID:gaku,項目名稱:1pass,代碼行數:67,代碼來源:client.go


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