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


Golang generic.Each函数代码示例

本文整理汇总了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
	}
}
开发者ID:normalnorman,项目名称:cli,代码行数:26,代码来源:manifest.go

示例2: walkManifestLookingForProperties

func walkManifestLookingForProperties(data generic.Map) (errs ManifestErrors) {
	generic.Each(data, func(key, value interface{}) {
		errs = append(errs, walkMapLookingForProperties(value)...)
	})

	return
}
开发者ID:normalnorman,项目名称:cli,代码行数:7,代码来源:manifest.go

示例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
}
开发者ID:normalnorman,项目名称:cli,代码行数:8,代码来源:manifest.go

示例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
}
开发者ID:normalnorman,项目名称:cli,代码行数:12,代码来源:manifest.go

示例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
}
开发者ID:julz,项目名称:cli,代码行数:12,代码来源:manifest.go

示例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
}
开发者ID:nsnt,项目名称:cli,代码行数:18,代码来源:helpers.go

示例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
}
开发者ID:juggernaut,项目名称:cli,代码行数:44,代码来源:manifest.go

示例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
	}
}
开发者ID:juggernaut,项目名称:cli,代码行数:40,代码来源:manifest.go

示例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
}
开发者ID:nsnt,项目名称:cli,代码行数:39,代码来源:fake_app_repo.go


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