本文整理汇总了Golang中github.com/cloudfoundry/cli/generic.Map类的典型用法代码示例。如果您正苦于以下问题:Golang Map类的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: sliceOrEmptyVal
func sliceOrEmptyVal(yamlMap generic.Map, key string, errs *[]error) *[]string {
if !yamlMap.Has(key) {
return new([]string)
}
var (
stringSlice []string
err error
)
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:vframbach,项目名称:cli,代码行数:33,代码来源: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:jsloyer,项目名称:cli,代码行数:29,代码来源:manifest.go
示例3: sliceOrEmptyVal
func sliceOrEmptyVal(yamlMap generic.Map, key string, errs *[]error) *[]string {
if !yamlMap.Has(key) {
return new([]string)
}
var (
stringSlice []string
err error
)
sliceErr := errors.NewWithFmt("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 = sliceErr
break
}
stringSlice = append(stringSlice, stringValue)
}
default:
err = sliceErr
}
if err != nil {
*errs = append(*errs, err)
return nil
}
return &stringSlice
}
开发者ID:nandrah,项目名称:cli,代码行数:33,代码来源:manifest.go
示例4: 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:Reejoshi,项目名称:cli,代码行数:30,代码来源:manifest.go
示例5: 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:vframbach,项目名称:cli,代码行数:10,代码来源:events.go
示例6: 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:vframbach,项目名称:cli,代码行数:31,代码来源:manifest.go
示例7: 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:vframbach,项目名称:cli,代码行数:12,代码来源:manifest.go
示例8: bytesVal
func bytesVal(yamlMap generic.Map, key string, errs *[]error) *uint64 {
yamlVal := yamlMap.Get(key)
if yamlVal == nil {
return nil
}
value, err := formatters.ToMegabytes(yamlVal.(string))
if err != nil {
*errs = append(*errs, errors.NewWithFmt("Unexpected value for %s :\n%s", key, err.Error()))
return nil
}
return &value
}
开发者ID:nandrah,项目名称: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:nandrah,项目名称:cli,代码行数:12,代码来源:manifest.go
示例10: 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 = errors.NewWithFmt("Expected %s to be a number, but it was a %T.", key, val)
}
if err != nil {
*errs = append(*errs, err)
return nil
}
return &intVal
}
开发者ID:nandrah,项目名称:cli,代码行数:26,代码来源:manifest.go
示例11: 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:vframbach,项目名称:cli,代码行数:27,代码来源:manifest.go
示例12: 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:vframbach,项目名称:cli,代码行数:18,代码来源:manifest.go
示例13: 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:vframbach,项目名称:cli,代码行数:19,代码来源:manifest.go
示例14: 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
} else {
return &val
}
case nil:
return &empty
default:
*errs = append(*errs, errors.NewWithFmt("%s must be a string or null value", key))
return nil
}
}
开发者ID:nandrah,项目名称:cli,代码行数:19,代码来源:manifest.go
示例15: 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:vframbach,项目名称:cli,代码行数:35,代码来源:manifest.go
示例16: 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, errors.NewWithFmt("Expected %s to be a boolean.", key))
return false
}
}
开发者ID:nandrah,项目名称:cli,代码行数:13,代码来源:manifest.go
示例17: 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:vframbach,项目名称:cli,代码行数:13,代码来源:manifest.go
示例18:
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating app", "my-new-app", "my-org", "my-space"},
[]string{"OK"},
[]string{"Creating", "my-new-app.private.cf-app.com"},
[]string{"OK"},
[]string{"Binding", "my-new-app.private.cf-app.com"},
[]string{"OK"},
[]string{"Uploading my-new-app"},
[]string{"OK"},
))
})
})
Describe("randomized hostnames", func() {
var manifestApp generic.Map
BeforeEach(func() {
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.FindByHostAndDomainCalledWith.Host).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)
开发者ID:matanzit,项目名称:cli,代码行数:30,代码来源:push_test.go
注:本文中的github.com/cloudfoundry/cli/generic.Map类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论