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


Golang Storage.Put方法代碼示例

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


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

示例1: copyOne

func copyOne(
	tool *state.Tools, source environs.StorageReader,
	target environs.Storage, ctx *cmd.Context,
) error {
	toolsName := tools.StorageName(tool.Binary)
	fmt.Fprintf(ctx.Stderr, "copying %v", toolsName)
	srcFile, err := source.Get(toolsName)
	if err != nil {
		return err
	}
	defer srcFile.Close()
	// We have to buffer the content, because Put requires the content
	// length, but Get only returns us a ReadCloser
	buf := &bytes.Buffer{}
	nBytes, err := io.Copy(buf, srcFile)
	if err != nil {
		return err
	}
	log.Infof("downloaded %v (%dkB), uploading", toolsName, (nBytes+512)/1024)
	fmt.Fprintf(ctx.Stderr, ", download %dkB, uploading\n", (nBytes+512)/1024)

	if err := target.Put(toolsName, buf, nBytes); err != nil {
		return err
	}
	return nil
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:26,代碼來源:synctools.go

示例2: restoreBootstrapVerificationFile

func restoreBootstrapVerificationFile(c *C, storage environs.Storage) {
	content := "juju-core storage writing verified: ok\n"
	contentReader := strings.NewReader(content)
	err := storage.Put("bootstrap-verify", contentReader,
		int64(len(content)))
	c.Assert(err, IsNil)
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:7,代碼來源:livetests.go

示例3: upload

func upload(s environs.Storage, v string) {
	vers := version.MustParseBinary(v)
	p := environs.ToolsStoragePath(vers)
	err := s.Put(p, strings.NewReader(v), int64(len(v)))
	if err != nil {
		panic(err)
	}
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:8,代碼來源:upgradejuju_test.go

示例4: setupSavedState

func (suite *StateSuite) setupSavedState(c *C, storage environs.Storage) environs.BootstrapState {
	arch := "amd64"
	state := environs.BootstrapState{
		StateInstances:  []instance.Id{instance.Id("an-instance-id")},
		Characteristics: []instance.HardwareCharacteristics{{Arch: &arch}}}
	content, err := goyaml.Marshal(state)
	c.Assert(err, IsNil)
	err = storage.Put(environs.StateFile, ioutil.NopCloser(bytes.NewReader(content)), int64(len(content)))
	c.Assert(err, IsNil)
	return state
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:11,代碼來源:state_test.go

示例5: uploadFakeToolsVersion

func uploadFakeToolsVersion(storage environs.Storage, vers version.Binary) (*state.Tools, error) {
	data := vers.String()
	name := tools.StorageName(vers)
	log.Noticef("environs/testing: uploading FAKE tools %s", vers)
	if err := storage.Put(name, strings.NewReader(data), int64(len(data))); err != nil {
		return nil, err
	}
	url, err := storage.URL(name)
	if err != nil {
		return nil, err
	}
	return &state.Tools{Binary: vers, URL: url}, nil
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:13,代碼來源:tools.go

示例6: storageCopy

func storageCopy(source environs.Storage, sourcePath string, target environs.Storage, targetPath string) error {
	rc, err := source.Get(sourcePath)
	if err != nil {
		return err
	}
	var buf bytes.Buffer
	_, err = io.Copy(&buf, rc)
	rc.Close()
	if err != nil {
		return err
	}
	return target.Put(targetPath, &buf, int64(buf.Len()))
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:13,代碼來源:livetests.go

示例7: checkRemoveAll

func checkRemoveAll(c *C, storage environs.Storage) {
	contents := []byte("File contents.")
	aFile := "a-file.txt"
	err := storage.Put(aFile, bytes.NewBuffer(contents), int64(len(contents)))
	c.Assert(err, IsNil)
	err = storage.Put("empty-file", bytes.NewBuffer(nil), 0)
	c.Assert(err, IsNil)

	err = storage.RemoveAll()
	c.Assert(err, IsNil)

	files, err := storage.List("")
	c.Assert(err, IsNil)
	c.Check(files, HasLen, 0)

	_, err = storage.Get(aFile)
	c.Assert(err, NotNil)
	c.Check(err, ErrorMatches, fmt.Sprintf("file %q not found", aFile))
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:19,代碼來源:storage_test.go


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