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


Golang MetaData.IsDefined方法代码示例

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


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

示例1: validateConfig

//check validation of config
func validateConfig(conf *Config, md *toml.MetaData) error {
	//for protection when debugging on non production environment
	var errStrings []string

	format := "[%s]"
	inValid := false
	for _, keys := range checkTomlKeys {
		if !md.IsDefined(keys...) {
			switch len(keys) {
			case 1:
				format = "[%s]"
			case 2:
				format = "[%s] %s"
			case 3:
				format = "[%s.%s] %s"
			default:
				//invalid check string
				inValid = true
				break
			}
			keysIfc := u.SliceStrToInterface(keys)
			errStrings = append(errStrings, fmt.Sprintf(format, keysIfc...))
		}
	}

	// Error
	if inValid {
		return errors.New("Error: Check Text has wrong number of parameter")
	}
	if len(errStrings) != 0 {
		return fmt.Errorf("Error: There are lacks of keys : %#v \n", errStrings)
	}

	return nil
}
开发者ID:hiromaily,项目名称:go-book-teacher,代码行数:36,代码来源:config.go

示例2: validateScriptsConf

func validateScriptsConf(scripts *ScriptsConf, meta toml.MetaData) error {
	if scripts == nil {
		return nil
	}
	if !meta.IsDefined("scripts", "path") {
		return errors.New("scripts section provided without path.")
	}
	if !meta.IsDefined("scripts", "run_interval_ms") {
		return errors.New("scripts section provided without run_interval_ms.")
	}
	if scripts.RunIntervalMS <= 0 {
		return errors.New("scripts.run_interval_ms must be positive")
	}
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:gost,代码行数:15,代码来源:conf.go

示例3: validateOSStatsConf

func validateOSStatsConf(osStats *OSStatsConf, meta toml.MetaData) error {
	if osStats == nil {
		return nil
	}
	if meta.IsDefined("os_stats", "check_interval_ms") {
		if osStats.CheckIntervalMS <= 0 {
			return errors.New("check_interval_ms must be positive")
		}
	}
	if err := validateMemConf(osStats.Mem); err != nil {
		return err
	}
	if err := validateCPUConf(osStats.CPU); err != nil {
		return err
	}
	// For now, any parseable NetConf is valid.
	for _, diskConf := range osStats.Disk {
		if err := validateDiskConf(diskConf); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:gost,代码行数:23,代码来源:conf.go

示例4: LoadContainerSettings

//Loads a container configuration object, overriding a base
//This function prevents empty TOML keys (anything you didn't specify) from overriding a preset value.
func LoadContainerSettings(base *Container, inc *Container, meta *toml.MetaData, key ...string) {

	if meta.IsDefined(append(key, "command")...) {
		base.Command = inc.Command
	}

	if meta.IsDefined(append(key, "folder")...) {
		base.Folder = inc.Folder
	}

	if meta.IsDefined(append(key, "privileged")...) {
		base.Privileged = inc.Privileged
	}

	if meta.IsDefined(append(key, "mounts")...) {
		base.Mounts = append(base.Mounts, inc.Mounts...)
	}

	if meta.IsDefined(append(key, "ports")...) {
		base.Ports = append(base.Ports, inc.Ports...)
	}

	if meta.IsDefined(append(key, "dns")...) {
		base.DNS = append(base.DNS, inc.DNS...)
	}

	if meta.IsDefined(append(key, "attach")...) {
		base.Attach = inc.Attach
	}

	if meta.IsDefined(append(key, "purge")...) {
		base.Purge = inc.Purge
	}

	if meta.IsDefined(append(key, "environment")...) {
		base.Environment = append(base.Environment, inc.Environment...)
	}
}
开发者ID:polydawn,项目名称:hroot,代码行数:40,代码来源:parse.go


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