本文整理汇总了Golang中github.com/cloudfoundry/cli/generic.Each函数的典型用法代码示例。如果您正苦于以下问题:Golang Each函数的具体用法?Golang Each怎么用?Golang Each使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Each函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: envVarOrEmptyMap
func envVarOrEmptyMap(yamlMap generic.Map, errs *[]error) *map[string]interface{} {
key := "env"
switch envVars := yamlMap.Get(key).(type) {
case nil:
aMap := make(map[string]interface{}, 0)
return &aMap
case map[string]interface{}:
yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
return envVarOrEmptyMap(yamlMap, errs)
case map[interface{}]interface{}:
yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
return envVarOrEmptyMap(yamlMap, errs)
case generic.Map:
merrs := validateEnvVars(envVars)
if merrs != nil {
*errs = append(*errs, merrs...)
return nil
}
result := make(map[string]interface{}, envVars.Count())
generic.Each(envVars, func(key, value interface{}) {
result[key.(string)] = value
})
return &result
default:
*errs = append(*errs, fmt.Errorf(T("Expected {{.Name}} to be a set of key => value, but it was a {{.Type}}.",
map[string]interface{}{"Name": key, "Type": envVars})))
return nil
}
}
示例2: validateEnvVars
func validateEnvVars(input generic.Map) (errs []error) {
generic.Each(input, func(key, value interface{}) {
if value == nil {
errs = append(errs, errors.New(fmt.Sprintf("env var '%s' should not be null", key)))
}
})
return
}
示例3: validateEnvVars
func validateEnvVars(input generic.Map) (errs []error) {
generic.Each(input, func(key, value interface{}) {
if value == nil {
errs = append(errs, fmt.Errorf(T("env var '{{.PropertyName}}' should not be null",
map[string]interface{}{"PropertyName": key})))
}
})
return
}
示例4: checkForNulls
func checkForNulls(yamlMap generic.Map) (errs []error) {
generic.Each(yamlMap, func(key interface{}, value interface{}) {
if key == "command" || key == "buildpack" {
return
}
if value == nil {
errs = append(errs, errors.NewWithFmt("%s should not be null", key))
}
})
return
}
示例5: checkForNulls
func checkForNulls(yamlMap generic.Map) error {
var errs []error
generic.Each(yamlMap, func(key interface{}, value interface{}) {
if key == "command" || key == "buildpack" {
return
}
if value == nil {
errs = append(errs, fmt.Errorf(T("{{.PropertyName}} should not be null", map[string]interface{}{"PropertyName": key})))
}
})
if len(errs) > 0 {
message := ""
for i := range errs {
message = message + fmt.Sprintf("%s\n", errs[i].Error())
}
return errors.New(message)
}
return nil
}
示例6: expandProperties
func expandProperties(input interface{}, babbler generator.WordGenerator) (interface{}, error) {
var errs []error
var output interface{}
switch input := input.(type) {
case string:
match := propertyRegex.FindStringSubmatch(input)
if match != nil {
if match[0] == "${random-word}" {
output = strings.Replace(input, "${random-word}", strings.ToLower(babbler.Babble()), -1)
} else {
err := fmt.Errorf(T("Property '{{.PropertyName}}' found in manifest. This feature is no longer supported. Please remove it and try again.",
map[string]interface{}{"PropertyName": match[0]}))
errs = append(errs, err)
}
} else {
output = input
}
case []interface{}:
outputSlice := make([]interface{}, len(input))
for index, item := range input {
itemOutput, itemErr := expandProperties(item, babbler)
if itemErr != nil {
errs = append(errs, itemErr)
break
}
outputSlice[index] = itemOutput
}
output = outputSlice
case map[interface{}]interface{}:
outputMap := make(map[interface{}]interface{})
for key, value := range input {
itemOutput, itemErr := expandProperties(value, babbler)
if itemErr != nil {
errs = append(errs, itemErr)
break
}
outputMap[key] = itemOutput
}
output = outputMap
case generic.Map:
outputMap := generic.NewMap()
generic.Each(input, func(key, value interface{}) {
itemOutput, itemErr := expandProperties(value, babbler)
if itemErr != nil {
errs = append(errs, itemErr)
return
}
outputMap.Set(key, itemOutput)
})
output = outputMap
default:
output = input
}
if len(errs) > 0 {
message := ""
for _, err := range errs {
message = message + fmt.Sprintf("%s\n", err.Error())
}
return nil, errors.New(message)
}
return output, nil
}