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


Golang generic.Map类代码示例

本文整理汇总了Golang中generic.Map的典型用法代码示例。如果您正苦于以下问题:Golang Map类的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sliceOrEmptyVal

func sliceOrEmptyVal(yamlMap generic.Map, key string, errs *ManifestErrors) *[]string {
	if !yamlMap.Has(key) {
		return new([]string)
	}

	var (
		stringSlice []string
		err         error
	)

	errMsg := fmt.Sprintf("Expected %s to be a list of strings.", key)

	switch input := yamlMap.Get(key).(type) {
	case []interface{}:
		for _, value := range input {
			stringValue, ok := value.(string)
			if !ok {
				err = errors.New(errMsg)
				break
			}
			stringSlice = append(stringSlice, stringValue)
		}
	default:
		err = errors.New(errMsg)
	}

	if err != nil {
		*errs = append(*errs, err)
		return nil
	}

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

示例2: 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

示例3: setStringSlice

func setStringSlice(appMap generic.Map, key string, val interface{}, errs *ManifestErrors) {
	var (
		stringSlice []string
		err         error
	)

	errMsg := fmt.Sprintf("Expected %s to be a list of strings.", key)

	switch input := val.(type) {
	case []interface{}:
		for _, value := range input {
			stringValue, ok := value.(string)
			if !ok {
				err = errors.New(errMsg)
				break
			}
			stringSlice = append(stringSlice, stringValue)
		}
	default:
		err = errors.New(errMsg)
	}

	if err != nil {
		*errs = append(*errs, err)
		return
	}

	appMap.Set(key, stringSlice)
	return
}
开发者ID:pmuellr,项目名称:cli,代码行数:30,代码来源:manifest.go

示例4: setStringVal

func setStringVal(appMap generic.Map, key string, val interface{}, errs *ManifestErrors) {
	stringVal, ok := val.(string)
	if !ok {
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string value", key)))
		return
	}
	appMap.Set(key, stringVal)
}
开发者ID:pmuellr,项目名称:cli,代码行数:8,代码来源:manifest.go

示例5: setBytesVal

func setBytesVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	value, err := formatters.ToMegabytes(yamlMap.Get(key).(string))
	if err != nil {
		*errs = append(*errs, errors.New(fmt.Sprintf("Unexpected value for %s :\n%s", key, err.Error())))
		return
	}
	appMap.Set(key, value)
}
开发者ID:nsnt,项目名称:cli,代码行数:8,代码来源:manifest.go

示例6: setStringOrNullVal

func setStringOrNullVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	switch val := yamlMap.Get(key).(type) {
	case string:
		appMap.Set(key, val)
	case nil:
		appMap.Set(key, "")
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string or null value", key)))
	}
}
开发者ID:nsnt,项目名称:cli,代码行数:10,代码来源:manifest.go

示例7: formatDescription

func formatDescription(metadata generic.Map, keys []string) string {
	parts := []string{}
	for _, key := range keys {
		value := metadata.Get(key)
		if value != nil {
			parts = append(parts, fmt.Sprintf("%s: %s", key, formatDescriptionPart(value)))
		}
	}
	return strings.Join(parts, ", ")
}
开发者ID:normalnorman,项目名称:cli,代码行数:10,代码来源:app_events.go

示例8: checkForNulls

func checkForNulls(appParams generic.Map) (errs ManifestErrors) {
	for key, _ := range manifestKeys {
		if key == "command" {
			continue
		}
		if appParams.IsNil(key) {
			errs = append(errs, errors.New(fmt.Sprintf("%s should not be null", key)))
		}
	}

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

示例9: stringVal

func stringVal(yamlMap generic.Map, key string, errs *[]error) *string {
	val := yamlMap.Get(key)
	if val == nil {
		return nil
	}
	result, ok := val.(string)
	if !ok {
		*errs = append(*errs, errors.NewWithFmt("%s must be a string value", key))
		return nil
	}
	return &result
}
开发者ID:julz,项目名称:cli,代码行数:12,代码来源:manifest.go

示例10: bytesVal

func bytesVal(yamlMap generic.Map, key string, errs *ManifestErrors) *uint64 {
	yamlVal := yamlMap.Get(key)
	if yamlVal == nil {
		return nil
	}
	value, err := formatters.ToMegabytes(yamlVal.(string))
	if err != nil {
		*errs = append(*errs, errors.New(fmt.Sprintf("Unexpected value for %s :\n%s", key, err.Error())))
		return nil
	}
	return &value
}
开发者ID:normalnorman,项目名称:cli,代码行数:12,代码来源:manifest.go

示例11: stringVal

func stringVal(yamlMap generic.Map, key string, errs *ManifestErrors) *string {
	val := yamlMap.Get(key)
	if val == nil {
		return nil
	}
	result, ok := val.(string)
	if !ok {
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string value", key)))
		return nil
	}
	return &result
}
开发者ID:normalnorman,项目名称:cli,代码行数:12,代码来源:manifest.go

示例12: setBoolVal

func setBoolVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	switch val := yamlMap.Get(key).(type) {
	case bool:
		appMap.Set(key, val)
	case string:
		boolVal := val == "true"
		appMap.Set(key, boolVal)
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a boolean.", key)))
	}

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

示例13: setEnvVar

func setEnvVar(appMap generic.Map, env interface{}, errs *ManifestErrors) {
	if !generic.IsMappable(env) {
		*errs = append(*errs, errors.New("Expected env vars to be a set of key => value."))
		return
	}

	merrs := validateEnvVars(env)
	if merrs != nil {
		*errs = append(*errs, merrs)
		return
	}

	appMap.Set("env", generic.NewMap(env))
}
开发者ID:pmuellr,项目名称:cli,代码行数:14,代码来源:manifest.go

示例14: stringOrNullVal

func stringOrNullVal(yamlMap generic.Map, key string, errs *ManifestErrors) *string {
	if !yamlMap.Has(key) {
		return nil
	}
	switch val := yamlMap.Get(key).(type) {
	case string:
		return &val
	case nil:
		empty := ""
		return &empty
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string or null value", key)))
		return nil
	}
}
开发者ID:normalnorman,项目名称:cli,代码行数:15,代码来源:manifest.go

示例15: mapToAppParams

func mapToAppParams(yamlMap generic.Map) (appParams cf.AppParams, errs ManifestErrors) {
	appParams = cf.NewEmptyAppParams()

	errs = checkForNulls(yamlMap)
	if !errs.Empty() {
		return
	}

	for key, handler := range manifestKeys {
		if yamlMap.Has(key) {
			handler(appParams, yamlMap, key, &errs)
		}
	}

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


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