本文整理汇总了Golang中github.com/juju/core/environs/storage.Storage.URL方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.URL方法的具体用法?Golang Storage.URL怎么用?Golang Storage.URL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/core/environs/storage.Storage
的用法示例。
在下文中一共展示了Storage.URL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateStateFile
// CreateStateFile creates an empty state file on the given storage, and
// returns its URL.
func CreateStateFile(stor storage.Storage) (string, error) {
err := putState(stor, []byte{})
if err != nil {
return "", fmt.Errorf("cannot create initial state file: %v", err)
}
return stor.URL(StateFile)
}
示例2: uploadFakeToolsVersion
func uploadFakeToolsVersion(stor storage.Storage, vers version.Binary) (*coretools.Tools, error) {
logger.Infof("uploading FAKE tools %s", vers)
tgz, checksum := coretesting.TarGz(
coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String()))
size := int64(len(tgz))
name := envtools.StorageName(vers)
if err := stor.Put(name, bytes.NewReader(tgz), size); err != nil {
return nil, err
}
url, err := stor.URL(name)
if err != nil {
return nil, err
}
return &coretools.Tools{URL: url, Version: vers, Size: size, SHA256: checksum}, nil
}
示例3: UploadToStorage
// UploadToStorage uploads tools and metadata for the specified versions to storage.
func UploadToStorage(c *gc.C, stor storage.Storage, versions ...version.Binary) map[version.Binary]string {
uploaded := map[version.Binary]string{}
if len(versions) == 0 {
return uploaded
}
var err error
for _, vers := range versions {
filename := fmt.Sprintf("tools/releases/tools-%s.tar.gz", vers.String())
// Put a file in images since the dummy storage provider requires a
// file to exist before the URL can be found. This is to ensure it behaves
// the same way as MAAS.
err = stor.Put(filename, strings.NewReader("dummy"), 5)
c.Assert(err, gc.IsNil)
uploaded[vers], err = stor.URL(filename)
c.Assert(err, gc.IsNil)
}
objects := generateMetadata(c, versions...)
for _, object := range objects {
toolspath := path.Join("tools", object.path)
err = stor.Put(toolspath, bytes.NewReader(object.data), int64(len(object.data)))
c.Assert(err, gc.IsNil)
}
return uploaded
}