本文整理匯總了Golang中generic.Each函數的典型用法代碼示例。如果您正苦於以下問題:Golang Each函數的具體用法?Golang Each怎麽用?Golang Each使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Each函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: envVarOrEmptyMap
func envVarOrEmptyMap(yamlMap generic.Map, errs *ManifestErrors) *map[string]string {
key := "env"
switch envVars := yamlMap.Get(key).(type) {
case nil:
aMap := make(map[string]string, 0)
return &aMap
case map[string]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]string, envVars.Count())
generic.Each(envVars, func(key, value interface{}) {
result[key.(string)] = value.(string)
})
return &result
default:
*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value.", key)))
return nil
}
}
示例2: walkManifestLookingForProperties
func walkManifestLookingForProperties(data generic.Map) (errs ManifestErrors) {
generic.Each(data, func(key, value interface{}) {
errs = append(errs, walkMapLookingForProperties(value)...)
})
return
}
示例3: validateEnvVars
func validateEnvVars(input generic.Map) (errs ManifestErrors) {
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
}
示例4: checkForNulls
func checkForNulls(yamlMap generic.Map) (errs ManifestErrors) {
generic.Each(yamlMap, func(key interface{}, value interface{}) {
if key == "command" {
return
}
if value == nil {
errs = append(errs, errors.New(fmt.Sprintf("%s should not be null", key)))
}
})
return
}
示例5: 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
}
示例6: mapToJsonValues
func mapToJsonValues(params generic.Map) (vals []string) {
generic.Each(params, func(key, val interface{}) {
switch val := val.(type) {
case string:
if val != "null" {
val = fmt.Sprintf(`"%s"`, val)
}
vals = append(vals, fmt.Sprintf(`"%s":%s`, key, val))
case int:
vals = append(vals, fmt.Sprintf(`"%s":%d`, key, val))
case uint64:
vals = append(vals, fmt.Sprintf(`"%s":%d`, key, val))
default:
vals = append(vals, fmt.Sprintf(`"%s":%s`, key, val))
}
})
return
}
示例7: expandProperties
func expandProperties(input interface{}, babbler words.WordGenerator) (output interface{}, errs ManifestErrors) {
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 := errors.New(fmt.Sprintf("Property '%s' found in manifest. This feature is no longer supported. Please remove it and try again.", match[0]))
errs = append(errs, err)
}
} else {
output = input
}
case []interface{}:
outputSlice := make([]interface{}, len(input))
for index, item := range input {
itemOutput, itemErrs := expandProperties(item, babbler)
outputSlice[index] = itemOutput
errs = append(errs, itemErrs...)
}
output = outputSlice
case map[interface{}]interface{}:
outputMap := make(map[interface{}]interface{})
for key, value := range input {
itemOutput, itemErrs := expandProperties(value, babbler)
outputMap[key] = itemOutput
errs = append(errs, itemErrs...)
}
output = outputMap
case generic.Map:
outputMap := generic.NewMap()
generic.Each(input, func(key, value interface{}) {
itemOutput, itemErrs := expandProperties(value, babbler)
outputMap.Set(key, itemOutput)
errs = append(errs, itemErrs...)
})
output = outputMap
default:
output = input
}
return
}
示例8: envVarOrEmptyMap
func envVarOrEmptyMap(yamlMap generic.Map, errs *ManifestErrors) *map[string]string {
key := "env"
switch envVars := yamlMap.Get(key).(type) {
case nil:
aMap := make(map[string]string, 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]string, envVars.Count())
generic.Each(envVars, func(key, value interface{}) {
switch value.(type) {
case string:
result[key.(string)] = value.(string)
case int64, int, int32:
result[key.(string)] = fmt.Sprintf("%d", value)
case float32, float64:
result[key.(string)] = fmt.Sprintf("%f", value)
default:
*errs = append(*errs, errors.New(fmt.Sprintf("Expected environment variable %s to have a string value, but it was a %T.", key, value)))
}
})
return &result
default:
*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value, but it was a %T.", key, envVars)))
return nil
}
}
示例9: Create
func (repo *FakeApplicationRepository) Create(params cf.AppParams) (resultApp cf.Application, apiResponse net.ApiResponse) {
if repo.CreateAppParams == nil {
repo.CreateAppParams = []cf.AppParams{}
}
repo.CreateAppParams = append(repo.CreateAppParams, params)
resultApp.Guid = params.Get("name").(string) + "-guid"
resultApp.Name = params.Get("name").(string)
resultApp.State = "stopped"
resultApp.EnvironmentVars = map[string]string{}
if params.NotNil("space_guid") {
resultApp.SpaceGuid = params.Get("space_guid").(string)
}
if params.NotNil("buildpack") {
resultApp.BuildpackUrl = params.Get("buildpack").(string)
}
if params.NotNil("command") {
resultApp.Command = params.Get("command").(string)
}
if params.NotNil("disk_quota") {
resultApp.DiskQuota = params.Get("disk_quota").(uint64)
}
if params.NotNil("instances") {
resultApp.InstanceCount = params.Get("instances").(int)
}
if params.NotNil("memory") {
resultApp.Memory = params.Get("memory").(uint64)
}
if params.NotNil("env") {
envVars := params.Get("env").(generic.Map)
generic.Each(envVars, func(key, val interface{}) {
resultApp.EnvironmentVars[key.(string)] = val.(string)
})
}
return
}