当前位置: 首页>>代码示例>>Golang>>正文


Golang Set.Values方法代码示例

本文整理汇总了Golang中github.com/coreos/fleet/pkg.Set.Values方法的典型用法代码示例。如果您正苦于以下问题:Golang Set.Values方法的具体用法?Golang Set.Values怎么用?Golang Set.Values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coreos/fleet/pkg.Set的用法示例。


在下文中一共展示了Set.Values方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetUnitStates

func (m *systemdUnitManager) GetUnitStates(filter pkg.Set) (map[string]*unit.UnitState, error) {
	// Unfortunately we need to lock for the entire operation to ensure we
	// have a consistent view of the hashes. Otherwise, Load/Unload
	// operations could mutate the hashes before we've retrieved the state
	// for every unit in the filter, since they won't necessarily all be
	// present in the initial ListUnits() call.
	fallback := false

	m.mutex.Lock()
	defer m.mutex.Unlock()
	dbusStatuses, err := m.systemd.ListUnitsByNames(filter.Values())

	if err != nil {
		fallback = true
		log.Debugf("ListUnitsByNames is not implemented in your systemd version (requires at least systemd 230), fallback to ListUnits: %v", err)
		dbusStatuses, err = m.systemd.ListUnits()
		if err != nil {
			return nil, err
		}
	}

	states := make(map[string]*unit.UnitState)
	for _, dus := range dbusStatuses {
		if fallback && !filter.Contains(dus.Name) {
			// If filter could not be applied on DBus side, we will filter unit files here
			continue
		}

		us := &unit.UnitState{
			LoadState:   dus.LoadState,
			ActiveState: dus.ActiveState,
			SubState:    dus.SubState,
		}
		if h, ok := m.hashes[dus.Name]; ok {
			us.UnitHash = h.String()
		}
		states[dus.Name] = us
	}

	// grab data on subscribed units that didn't show up in ListUnits in fallback mode, most
	// likely due to being inactive
	if fallback {
		for _, name := range filter.Values() {
			if _, ok := states[name]; ok {
				continue
			}

			us, err := m.getUnitState(name)
			if err != nil {
				return nil, err
			}
			if h, ok := m.hashes[name]; ok {
				us.UnitHash = h.String()
			}
			states[name] = us
		}
	}

	return states, nil
}
开发者ID:jonboulle,项目名称:fleet,代码行数:60,代码来源:manager.go

示例2: GetUnitStates

func (fum *FakeUnitManager) GetUnitStates(filter pkg.Set) (map[string]*UnitState, error) {
	fum.RLock()
	defer fum.RUnlock()

	states := make(map[string]*UnitState)
	for _, name := range filter.Values() {
		if _, ok := fum.u[name]; ok {
			states[name] = &UnitState{"loaded", "active", "running", "", "", name}
		}
	}

	return states, nil
}
开发者ID:Blystad,项目名称:deis,代码行数:13,代码来源:fake.go

示例3: GetUnitStates

func (m *systemdUnitManager) GetUnitStates(filter pkg.Set) (map[string]*unit.UnitState, error) {
	// Unfortunately we need to lock for the entire operation to ensure we
	// have a consistent view of the hashes. Otherwise, Load/Unload
	// operations could mutate the hashes before we've retrieved the state
	// for every unit in the filter, since they won't necessarily all be
	// present in the initial ListUnits() call.
	m.mutex.Lock()
	defer m.mutex.Unlock()
	dbusStatuses, err := m.systemd.ListUnits()

	if err != nil {
		return nil, err
	}

	states := make(map[string]*unit.UnitState)
	for _, dus := range dbusStatuses {
		if !filter.Contains(dus.Name) {
			continue
		}

		us := &unit.UnitState{
			LoadState:   dus.LoadState,
			ActiveState: dus.ActiveState,
			SubState:    dus.SubState,
		}
		if h, ok := m.hashes[dus.Name]; ok {
			us.UnitHash = h.String()
		}
		states[dus.Name] = us
	}

	// grab data on subscribed units that didn't show up in ListUnits, most
	// likely due to being inactive
	for _, name := range filter.Values() {
		if _, ok := states[name]; ok {
			continue
		}

		us, err := m.getUnitState(name)
		if err != nil {
			return nil, err
		}
		if h, ok := m.hashes[name]; ok {
			us.UnitHash = h.String()
		}
		states[name] = us
	}

	return states, nil
}
开发者ID:ericcapricorn,项目名称:fleet,代码行数:50,代码来源:manager.go


注:本文中的github.com/coreos/fleet/pkg.Set.Values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。