當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。