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


Golang Map.Set方法代码示例

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


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

示例1: setSliceOrEmptyVal

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

	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
	}

	appMap.Set(key, stringSlice)
	return
}
开发者ID:nsnt,项目名称:cli,代码行数:35,代码来源: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: 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

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

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

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

示例8: setEnvVarOrEmptyMap

func setEnvVarOrEmptyMap(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	if !yamlMap.Has(key) {
		appMap.Set(key, generic.NewMap())
		return
	}

	envVars := yamlMap.Get(key)

	if !generic.IsMappable(envVars) {
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value.", key)))
		return
	}

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

	appMap.Set(key, generic.NewMap(envVars))
}
开发者ID:nsnt,项目名称:cli,代码行数:21,代码来源:manifest.go

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

示例10: setTimeoutVal

func setTimeoutVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	var (
		intVal int
		err    error
	)

	switch val := yamlMap.Get(key).(type) {
	case string:
		intVal, err = strconv.Atoi(val)
	case int:
		intVal = val
	default:
		err = errors.New("Expected health_check_timeout to be a number.")
	}

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

	appMap.Set("health_check_timeout", intVal)
}
开发者ID:nsnt,项目名称:cli,代码行数:22,代码来源:manifest.go

示例11: setIntVal

func setIntVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	var (
		intVal int
		err    error
	)

	switch val := yamlMap.Get(key).(type) {
	case string:
		intVal, err = strconv.Atoi(val)
	case int:
		intVal = val
	default:
		err = errors.New(fmt.Sprintf("Expected %s to be a number.", key))
	}

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

	appMap.Set(key, intVal)
}
开发者ID:nsnt,项目名称:cli,代码行数:22,代码来源:manifest.go

示例12:

		BeforeEach(func() {
			appRepo.ReadNotFound = true

			manifest := singleAppManifest()
			manifestApp = manifest.Data.Get("applications").([]interface{})[0].(generic.Map)
			manifestApp.Delete("host")
			manifestRepo.ReadManifestReturns.Manifest = manifest
		})

		It("provides a random hostname when the --random-route flag is passed", func() {
			callPush("--random-route", "my-new-app")
			Expect(routeRepo.FindByHostAndDomainHost).To(Equal("my-new-app-laughing-cow"))
		})

		It("provides a random hostname when the random-route option is set in the manifest", func() {
			manifestApp.Set("random-route", true)

			callPush("my-new-app")

			Expect(routeRepo.FindByHostAndDomainHost).To(Equal("my-new-app-laughing-cow"))
		})
	})

	It("creates an app when pushing for the first time", func() {
		routeRepo.FindByHostAndDomainErr = true
		appRepo.ReadNotFound = true

		callPush("-t", "111", "my-new-app")
		Expect(*appRepo.CreatedAppParams().Name).To(Equal("my-new-app"))
		Expect(*appRepo.CreatedAppParams().SpaceGuid).To(Equal("my-space-guid"))
开发者ID:juggernaut,项目名称:cli,代码行数:30,代码来源:push_test.go


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