• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang generic.Each函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang generic.NewMap函数代码示例发布时间:2022-05-24
下一篇:
Golang thrifttest.ThriftTestClient类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap