當前位置: 首頁>>代碼示例>>Golang>>正文


Golang generic.Map類代碼示例

本文整理匯總了Golang中code/cloudfoundry/org/cli/utils/generic.Map的典型用法代碼示例。如果您正苦於以下問題:Golang Map類的具體用法?Golang Map怎麽用?Golang Map使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Map類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parseRoutes

func parseRoutes(input generic.Map, errs *[]error) []models.ManifestRoute {
	if !input.Has("routes") {
		return nil
	}

	genericRoutes, ok := input.Get("routes").([]interface{})
	if !ok {
		*errs = append(*errs, fmt.Errorf(T("'routes' should be a list")))
		return nil
	}

	manifestRoutes := []models.ManifestRoute{}
	for _, genericRoute := range genericRoutes {
		route, ok := genericRoute.(map[interface{}]interface{})
		if !ok {
			*errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property")))
			continue
		}

		if routeVal, exist := route["route"]; exist {
			manifestRoutes = append(manifestRoutes, models.ManifestRoute{
				Route: routeVal.(string),
			})
		} else {
			*errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property")))
		}
	}

	return manifestRoutes
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:30,代碼來源:manifest.go

示例2: intSliceVal

func intSliceVal(yamlMap generic.Map, key string, errs *[]error) *[]int {
	if !yamlMap.Has(key) {
		return nil
	}

	err := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of integers.", map[string]interface{}{"PropertyName": key}))

	s, ok := yamlMap.Get(key).([]interface{})

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

	var intSlice []int

	for _, el := range s {
		intValue, ok := el.(int)

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

		intSlice = append(intSlice, intValue)
	}

	return &intSlice
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:29,代碼來源:manifest.go

示例3: sliceOrNil

func sliceOrNil(yamlMap generic.Map, key string, errs *[]error) []string {
	if !yamlMap.Has(key) {
		return nil
	}

	var err error
	stringSlice := []string{}

	sliceErr := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of strings.", map[string]interface{}{"PropertyName": key}))

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

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

	return stringSlice
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:manifest.go

示例4: 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:fujitsu-cf,項目名稱:cli,代碼行數:10,代碼來源:events.go

示例5: 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
	}
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:manifest.go

示例6: 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, fmt.Errorf(T("{{.PropertyName}} must be a string value", map[string]interface{}{"PropertyName": key})))
		return nil
	}
	return &result
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:12,代碼來源:manifest.go

示例7: intVal

func intVal(yamlMap generic.Map, key string, errs *[]error) *int {
	var (
		intVal int
		err    error
	)

	switch val := yamlMap.Get(key).(type) {
	case string:
		intVal, err = strconv.Atoi(val)
	case int:
		intVal = val
	case int64:
		intVal = int(val)
	case nil:
		return nil
	default:
		err = fmt.Errorf(T("Expected {{.PropertyName}} to be a number, but it was a {{.PropertyType}}.",
			map[string]interface{}{"PropertyName": key, "PropertyType": val}))
	}

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

	return &intVal
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:27,代碼來源:manifest.go

示例8: stringValOrDefault

func stringValOrDefault(yamlMap generic.Map, key string, errs *[]error) *string {
	if !yamlMap.Has(key) {
		return nil
	}
	empty := ""
	switch val := yamlMap.Get(key).(type) {
	case string:
		if val == "default" {
			return &empty
		}
		return &val
	case nil:
		return &empty
	default:
		*errs = append(*errs, fmt.Errorf(T("{{.PropertyName}} must be a string or null value", map[string]interface{}{"PropertyName": key})))
		return nil
	}
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:18,代碼來源:manifest.go

示例9: bytesVal

func bytesVal(yamlMap generic.Map, key string, errs *[]error) *int64 {
	yamlVal := yamlMap.Get(key)
	if yamlVal == nil {
		return nil
	}

	stringVal := coerceToString(yamlVal)
	value, err := formatters.ToMegabytes(stringVal)
	if err != nil {
		*errs = append(*errs, fmt.Errorf(T("Invalid value for '{{.PropertyName}}': {{.StringVal}}\n{{.Error}}",
			map[string]interface{}{
				"PropertyName": key,
				"Error":        err.Error(),
				"StringVal":    stringVal,
			})))
		return nil
	}
	return &value
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:19,代碼來源:manifest.go

示例10: getAppMaps

func (m Manifest) getAppMaps(data generic.Map) ([]generic.Map, error) {
	globalProperties := data.Except([]interface{}{"applications"})

	var apps []generic.Map
	var errs []error
	if data.Has("applications") {
		appMaps, ok := data.Get("applications").([]interface{})
		if !ok {
			return []generic.Map{}, errors.New(T("Expected applications to be a list"))
		}

		for _, appData := range appMaps {
			if !generic.IsMappable(appData) {
				errs = append(errs, fmt.Errorf(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'",
					map[string]interface{}{"YmlSnippet": appData})))
				continue
			}

			appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
			apps = append(apps, appMap)
		}
	} else {
		apps = append(apps, globalProperties)
	}

	if len(errs) > 0 {
		message := ""
		for i := range errs {
			message = message + fmt.Sprintf("%s\n", errs[i].Error())
		}
		return []generic.Map{}, errors.New(message)
	}

	return apps, nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:35,代碼來源:manifest.go

示例11: boolVal

func boolVal(yamlMap generic.Map, key string, errs *[]error) bool {
	switch val := yamlMap.Get(key).(type) {
	case nil:
		return false
	case bool:
		return val
	case string:
		return val == "true"
	default:
		*errs = append(*errs, fmt.Errorf(T("Expected {{.PropertyName}} to be a boolean.", map[string]interface{}{"PropertyName": key})))
		return false
	}
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:13,代碼來源:manifest.go


注:本文中的code/cloudfoundry/org/cli/utils/generic.Map類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。