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


Golang Data.GetKey方法代码示例

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


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

示例1: loadFloat

func loadFloat(dat *wini.Data, name, key string, target *float64) {
	k := dat.GetKey(name, key)
	if k == nil {
		utils.Fail("Missing key " + key + " in section " + name)
	}

	tmp, err := k.Floats()
	utils.FailMeMaybe(err)

	if len(tmp) > 0 {
		*target = tmp[0]
	} else {
		utils.Fail("Missing key " + key + " in section " + name)
	}
}
开发者ID:AmandaCameron,项目名称:gobar,代码行数:15,代码来源:config.go

示例2: loadString

func loadString(dat *wini.Data, name, key, def string, target *string) {
	k := dat.GetKey(name, key)
	if k == nil {
		if def == "" {
			utils.Fail("Missing key " + key + " in section " + name)
		} else {
			*target = def
			return
		}
	}

	tmp := k.Strings()

	if len(tmp) > 0 {
		*target = tmp[0]
	} else {
		if def == "" {
			utils.Fail("Missing key " + key + " in section " + name)
		} else {
			*target = def
			return
		}
	}
}
开发者ID:AmandaCameron,项目名称:gobar,代码行数:24,代码来源:config.go

示例3: readSection

// readSection loads a particular section from the configuration file into
// the hook groups. One section may result in the same hook being added to
// multiple groups.
func readSection(cdata *wini.Data, section string) error {
	// First lets roll up the match conditions.
	match := cdata.GetKey(section, "match")
	if match == nil {
		return fmt.Errorf("Could not find 'match' in the '%s' hook.", section)
	}

	satisfies := make([]string, len(match.Strings()))
	copy(satisfies, match.Strings())

	// Check each satisfies command to make sure it's a valid Gribble command.
	if cmd, err := checkCommands(satisfies); err != nil {
		return fmt.Errorf("The match command '%s' in the '%s' hook could "+
			"not be parsed: %s", cmd, section, err)
	}

	// Now try to find whether it's a conjunction or not.
	conjunction := true
	conjunctionKey := cdata.GetKey(section, "conjunction")
	if conjunctionKey != nil {
		if vals, err := conjunctionKey.Bools(); err != nil {
			logger.Warning.Println(err)
		} else {
			conjunction = vals[0]
		}
	}

	// Now traverse all of the keys in the section. We'll skip "match" since
	// we've already grabbed the data. Any other key should correspond to
	// a hook group name.
	addedOne := false
	for _, key := range cdata.Keys(section) {
		groupName := Type(key.Name())
		if groupName == "match" || groupName == "conjunction" {
			continue
		}
		if _, ok := groups[groupName]; !ok {
			return fmt.Errorf("Unrecognized hook group '%s' in the '%s' hook.",
				groupName, section)
		}

		consequences := make([]string, len(key.Strings()))
		copy(consequences, key.Strings())

		// Check each consequent command to make sure it's valid.
		if cmd, err := checkCommands(consequences); err != nil {
			return fmt.Errorf("The '%s' command '%s' in the '%s' hook could "+
				"not be parsed: %s", groupName, cmd, section, err)
		}
		hook := hook{
			name:         section,
			satisfies:    satisfies,
			conjunction:  conjunction,
			consequences: consequences,
		}
		groups[groupName] = append(groups[groupName], hook)
		addedOne = true
	}
	if !addedOne {
		return fmt.Errorf(
			"No hook groups were detected in the '%s' hook.", section)
	}
	return nil
}
开发者ID:flying99999,项目名称:wingo,代码行数:67,代码来源:hook.go


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