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