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


Golang utils.WriteYaml函數代碼示例

本文整理匯總了Golang中github.com/juju/utils.WriteYaml函數的典型用法代碼示例。如果您正苦於以下問題:Golang WriteYaml函數的具體用法?Golang WriteYaml怎麽用?Golang WriteYaml使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: Write

// Write atomically writes to disk the relation state change in hi.
// It must be called after the respective hook was executed successfully.
// Write doesn't validate hi but guarantees that successive writes of
// the same hi are idempotent.
func (d *StateDir) Write(hi hook.Info) (err error) {
	defer errors.Maskf(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.RemoteUnit)
	if hi.Kind == hooks.RelationBroken {
		return d.Remove()
	}
	name := strings.Replace(hi.RemoteUnit, "/", "-", 1)
	path := filepath.Join(d.path, name)
	if hi.Kind == hooks.RelationDeparted {
		if err = os.Remove(path); err != nil && !os.IsNotExist(err) {
			return err
		}
		// If atomic delete succeeded, update own state.
		delete(d.state.Members, hi.RemoteUnit)
		return nil
	}
	di := diskInfo{&hi.ChangeVersion, hi.Kind == hooks.RelationJoined}
	if err := utils.WriteYaml(path, &di); err != nil {
		return err
	}
	// If write was successful, update own state.
	d.state.Members[hi.RemoteUnit] = hi.ChangeVersion
	if hi.Kind == hooks.RelationJoined {
		d.state.ChangedPending = hi.RemoteUnit
	} else {
		d.state.ChangedPending = ""
	}
	return nil
}
開發者ID:kapilt,項目名稱:juju,代碼行數:32,代碼來源:relation.go

示例2: Write

// Write stores the supplied status information to disk.
func (f *StateFile) Write(code, info string) error {
	st := state{
		Code: code,
		Info: info,
	}
	return errors.Trace(utils.WriteYaml(f.path, st))
}
開發者ID:kakamessi99,項目名稱:juju,代碼行數:8,代碼來源:state.go

示例3: storeManifest

// storeManifest stores, into dataPath, the supplied manifest for the supplied charm.
func (d *manifestDeployer) storeManifest(url *charm.URL, manifest set.Strings) error {
	if err := os.MkdirAll(d.DataPath(manifestsDataPath), 0755); err != nil {
		return err
	}
	name := charm.Quote(url.String())
	path := filepath.Join(d.DataPath(manifestsDataPath), name)
	return utils.WriteYaml(path, manifest.SortedValues())
}
開發者ID:imoapps,項目名稱:juju,代碼行數:9,代碼來源:manifest_deployer.go

示例4: Write

// Write stores the supplied status information to disk.
func (f *StateFile) Write(code, info string, disconnected *Disconnected) error {
	st := state{
		Code:         code,
		Info:         info,
		Disconnected: disconnected,
	}

	return errors.Trace(utils.WriteYaml(f.path, st))
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:10,代碼來源:state.go

示例5: Write

// Write stores the supplied state to the file.
func (f *StateFile) Write(started bool, op Op, step OpStep, hi *uhook.Info, url *charm.URL) error {
	st := &State{
		Started:  started,
		Op:       op,
		OpStep:   step,
		Hook:     hi,
		CharmURL: url,
	}
	if err := st.validate(); err != nil {
		panic(err)
	}
	return utils.WriteYaml(f.path, st)
}
開發者ID:kapilt,項目名稱:juju,代碼行數:14,代碼來源:state.go

示例6: CommitHook

// CommitHook atomically writes to disk the storage state change in hi.
// It must be called after the respective hook was executed successfully.
// CommitHook doesn't validate hi but guarantees that successive writes
// of the same hi are idempotent.
func (d *stateFile) CommitHook(hi hook.Info) (err error) {
	defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.StorageId)
	if hi.Kind == hooks.StorageDetaching {
		return d.Remove()
	}
	attached := true
	di := diskInfo{&attached}
	if err := utils.WriteYaml(d.path, &di); err != nil {
		return err
	}
	// If write was successful, update own state.
	d.state.attached = true
	return nil
}
開發者ID:imoapps,項目名稱:juju,代碼行數:18,代碼來源:state.go

示例7: writeFilesystemInfo

func (s *tmpfsFilesystemSource) writeFilesystemInfo(tag names.FilesystemTag, info storage.FilesystemInfo) error {
	filename := s.filesystemInfoFile(tag)
	if _, err := os.Stat(filename); err == nil {
		return errors.Errorf("filesystem %v already exists", tag.Id())
	}
	if err := ensureDir(s.dirFuncs, filepath.Dir(filename)); err != nil {
		return errors.Trace(err)
	}
	err := utils.WriteYaml(filename, filesystemInfo{&info.Size})
	if err != nil {
		return errors.Annotate(err, "writing filesystem info to disk")
	}
	return err
}
開發者ID:xushiwei,項目名稱:juju,代碼行數:14,代碼來源:tmpfs.go

示例8: TestStates

func (s *StateFileSuite) TestStates(c *gc.C) {
	for i, t := range stateTests {
		c.Logf("test %d", i)
		path := filepath.Join(c.MkDir(), "uniter")
		file := operation.NewStateFile(path)
		_, err := file.Read()
		c.Assert(err, gc.Equals, operation.ErrNoStateFile)

		err = file.Write(&t.st)
		if t.err == "" {
			c.Assert(err, jc.ErrorIsNil)
		} else {
			c.Assert(err, gc.ErrorMatches, "invalid operation state: "+t.err)
			err := utils.WriteYaml(path, &t.st)
			c.Assert(err, jc.ErrorIsNil)
			_, err = file.Read()
			c.Assert(err, gc.ErrorMatches, `cannot read ".*": invalid operation state: `+t.err)
			continue
		}
		st, err := file.Read()
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(st, jc.DeepEquals, &t.st)
	}
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:24,代碼來源:state_test.go

示例9: WriteCharmURL

// WriteCharmURL writes a charm identity file into the supplied path.
func WriteCharmURL(path string, url *charm.URL) error {
	return utils.WriteYaml(path, url.String())
}
開發者ID:bac,項目名稱:juju,代碼行數:4,代碼來源:charm.go

示例10: writeOldState

func (s *upgradeStateContextSuite) writeOldState(c *gc.C, state *oldState) {
	err := utils.WriteYaml(s.uniterStateFile, state)
	c.Assert(err, jc.ErrorIsNil)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:4,代碼來源:upgrade123_test.go

示例11: Write

// Write stores the supplied state to the file.
func (f *StateFile) Write(st *State) error {
	if err := st.validate(); err != nil {
		return errors.Trace(err)
	}
	return utils.WriteYaml(f.path, st)
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:7,代碼來源:state.go


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