本文整理汇总了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
}
示例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
}
示例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
}
示例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...)
}
}