本文整理汇总了Golang中github.com/juju/juju/environs/storage.Storage.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.Get方法的具体用法?Golang Storage.Get怎么用?Golang Storage.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs/storage.Storage
的用法示例。
在下文中一共展示了Storage.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: metadataUnchanged
// metadataUnchanged returns true if the content of metadata for stream in stor is the same
// as generatedMetadata, ignoring the "updated" attribute.
func metadataUnchanged(stor storage.Storage, stream string, generatedMetadata []byte) (bool, error) {
mdPath := ProductMetadataPath(stream)
filePath := path.Join(storage.BaseToolsPath, mdPath)
existingDataReader, err := stor.Get(filePath)
// If the file can't be retrieved, consider it has changed.
if err != nil {
return false, nil
}
defer existingDataReader.Close()
existingData, err := ioutil.ReadAll(existingDataReader)
if err != nil {
return false, err
}
// To do the comparison, we unmarshall the metadata, clear the
// updated value, and marshall back to a string.
existingMetadata, err := removeMetadataUpdated(existingData)
if err != nil {
return false, err
}
newMetadata, err := removeMetadataUpdated(generatedMetadata)
if err != nil {
return false, err
}
return existingMetadata == newMetadata, nil
}
示例2: SignFileData
func SignFileData(stor storage.Storage, fileName string) error {
r, err := stor.Get(fileName)
if err != nil {
return err
}
defer r.Close()
fileData, err := ioutil.ReadAll(r)
if err != nil {
return err
}
signedName, signedContent, err := sstesting.SignMetadata(fileName, fileData)
if err != nil {
return err
}
err = stor.Put(signedName, strings.NewReader(string(signedContent)), int64(len(string(signedContent))))
if err != nil {
return err
}
return nil
}