本文整理汇总了Golang中generic.NewMap函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMap函数的具体用法?Golang NewMap怎么用?Golang NewMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 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{}) {
result[key.(string)] = value.(string)
})
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:popeye17,项目名称:cli,代码行数:29,代码来源:manifest.go
示例2: singleAppManifest
func singleAppManifest() *manifest.Manifest {
return &manifest.Manifest{
Path: "manifest.yml",
Data: generic.NewMap(map[interface{}]interface{}{
"applications": []interface{}{
generic.NewMap(map[interface{}]interface{}{
"name": "manifest-app-name",
"memory": "128MB",
"instances": 1,
"host": "manifest-host",
"domain": "manifest-example.com",
"stack": "custom-stack",
"timeout": 360,
"buildpack": "some-buildpack",
"command": `JAVA_HOME=$PWD/.openjdk JAVA_OPTS="-Xss995K" ./bin/start.sh run`,
"path": filepath.Clean("some/path/from/manifest"),
"env": generic.NewMap(map[interface{}]interface{}{
"FOO": "baz",
"PATH": "/u/apps/my-app/bin",
}),
}),
},
}),
}
}
开发者ID:juggernaut,项目名称:cli,代码行数:25,代码来源:push_test.go
示例3: ToFields
func (resource EventResourceNewV2) ToFields() models.EventFields {
metadata := generic.NewMap(resource.Entity.Metadata)
if metadata.Has("request") {
metadata = generic.NewMap(metadata.Get("request"))
}
return models.EventFields{
Guid: resource.Metadata.Guid,
Name: resource.Entity.Type,
Timestamp: resource.Entity.Timestamp,
Description: formatDescription(metadata, KNOWN_METADATA_KEYS),
}
}
开发者ID:normalnorman,项目名称:cli,代码行数:13,代码来源:app_events.go
示例4: ToFields
func (resource EventResourceNewV2) ToFields() models.EventFields {
metadata := generic.NewMap(resource.Entity.Metadata)
if metadata.Has("request") {
metadata = generic.NewMap(metadata.Get("request"))
}
return models.EventFields{
Guid: resource.Metadata.Guid,
Name: resource.Entity.Type,
Timestamp: resource.Entity.Timestamp,
Description: formatDescription(metadata, knownMetadataKeys),
ActorName: resource.Entity.ActorName,
}
}
开发者ID:nota-ja,项目名称:cli,代码行数:14,代码来源:events.go
示例5: TestParsingManifestWithNulls
func TestParsingManifestWithNulls(t *testing.T) {
_, errs := manifest.NewManifest(generic.NewMap(map[string]interface{}{
"applications": []interface{}{
map[string]interface{}{
"buildpack": nil,
"disk_quota": nil,
"domain": nil,
"host": nil,
"name": nil,
"path": nil,
"stack": nil,
"memory": nil,
"instances": nil,
"timeout": nil,
"no-route": nil,
"services": nil,
"env": nil,
},
},
}))
assert.Error(t, errs)
errorSlice := strings.Split(errs.Error(), "\n")
manifestKeys := []string{"buildpack", "disk_quota", "domain", "host", "name", "path", "stack",
"memory", "instances", "timeout", "no-route", "services", "env"}
for _, key := range manifestKeys {
testassert.SliceContains(t, errorSlice, testassert.Lines{{key, "not be null"}})
}
}
开发者ID:nsnt,项目名称:cli,代码行数:30,代码来源:manifest_test.go
示例6: getAppMaps
func (m Manifest) getAppMaps(data generic.Map) (apps []generic.Map, errs []error) {
globalProperties := data.Except([]interface{}{"applications"})
if data.Has("applications") {
appMaps, ok := data.Get("applications").([]interface{})
if !ok {
errs = append(errs, errors.New("Expected applications to be a list"))
return
}
for _, appData := range appMaps {
if !generic.IsMappable(appData) {
errs = append(errs, errors.New(fmt.Sprintf("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'%s'", appData)))
continue
}
appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
apps = append(apps, appMap)
}
} else {
apps = append(apps, globalProperties)
}
return
}
开发者ID:juggernaut,项目名称:cli,代码行数:25,代码来源:manifest.go
示例7: Applications
func (m Manifest) Applications() (apps []models.AppParams, err error) {
rawData, errs := expandProperties(m.Data, words.NewWordGenerator())
if len(errs) > 0 {
err = errors.NewWithSlice(errs)
return
}
data := generic.NewMap(rawData)
appMaps, errs := m.getAppMaps(data)
if len(errs) > 0 {
err = errors.NewWithSlice(errs)
return
}
for _, appMap := range appMaps {
app, errs := mapToAppParams(filepath.Dir(m.Path), appMap)
if len(errs) > 0 {
err = errors.NewWithSlice(errs)
continue
}
apps = append(apps, app)
}
return
}
开发者ID:julz,项目名称:cli,代码行数:26,代码来源:manifest.go
示例8: mapToAppSet
func mapToAppSet(basePath string, data generic.Map) (appSet []models.AppParams, errs ManifestErrors) {
if data.Has("applications") {
appMaps, ok := data.Get("applications").([]interface{})
if !ok {
errs = append(errs, errors.New("Expected applications to be a list"))
return
}
// we delete applications so that we may merge top level app params into each app
data.Delete("applications")
for _, appData := range appMaps {
if !generic.IsMappable(appData) {
errs = append(errs, errors.New("Expected application to be a dictionary"))
continue
}
appMap := generic.DeepMerge(data, generic.NewMap(appData))
appParams, appErrs := mapToAppParams(basePath, appMap)
if !appErrs.Empty() {
errs = append(errs, appErrs)
continue
}
appSet = append(appSet, appParams)
}
}
return
}
开发者ID:normalnorman,项目名称:cli,代码行数:31,代码来源:manifest.go
示例9: ToParams
func (model Application) ToParams() (params AppParams) {
params = NewAppParams(generic.NewMap(map[interface{}]interface{}{
"guid": model.Guid,
"name": model.Name,
"buildpack": model.BuildpackUrl,
"command": model.Command,
"disk_quota": model.DiskQuota,
"instances": model.InstanceCount,
"memory": model.Memory,
"state": strings.ToUpper(model.State),
"stack_guid": model.Stack.Guid,
"space_guid": model.SpaceGuid,
"env": generic.NewMap(model.EnvironmentVars),
}))
return
}
开发者ID:nsnt,项目名称:cli,代码行数:17,代码来源:domain.go
示例10: validateEnvVars
func validateEnvVars(input interface{}) (errs ManifestErrors) {
envVars := generic.NewMap(input)
generic.Each(envVars, func(key, value interface{}) {
if value == nil {
errs = append(errs, errors.New(fmt.Sprintf("env var '%s' should not be null", key)))
}
})
return
}
开发者ID:nsnt,项目名称:cli,代码行数:9,代码来源:manifest.go
示例11: TestParsingEmptyManifestDoesNotSetCommand
func TestParsingEmptyManifestDoesNotSetCommand(t *testing.T) {
m, err := manifest.NewManifest(generic.NewMap(map[string]interface{}{
"applications": []interface{}{
map[string]interface{}{},
},
}))
assert.NoError(t, err)
assert.False(t, m.Applications[0].Has("command"))
}
开发者ID:nsnt,项目名称:cli,代码行数:10,代码来源:manifest_test.go
示例12: manifestWithServicesAndEnv
func manifestWithServicesAndEnv() *manifest.Manifest {
return &manifest.Manifest{
Applications: []cf.AppParams{
cf.NewAppParams(generic.NewMap(map[interface{}]interface{}{
"name": "app1",
"services": []string{"app1-service", "global-service"},
"env": generic.NewMap(map[string]interface{}{
"SOMETHING": "definitely-something",
}),
})),
cf.NewAppParams(generic.NewMap(map[interface{}]interface{}{
"name": "app2",
"services": []string{"app2-service", "global-service"},
"env": generic.NewMap(map[string]interface{}{
"SOMETHING": "nothing",
}),
})),
},
}
}
开发者ID:nsnt,项目名称:cli,代码行数:20,代码来源:push_test.go
示例13: TestManifestWithInheritance
func TestManifestWithInheritance(t *testing.T) {
repo := NewManifestDiskRepository()
m, err := repo.ReadManifest("../../fixtures/inherited-manifest.yml")
assert.NoError(t, err)
assert.Equal(t, m.Applications[0].Get("name"), "base-app")
assert.Equal(t, m.Applications[0].Get("services"), []string{"base-service"})
assert.Equal(t, m.Applications[0].Get("env"), generic.NewMap(map[string]string{
"foo": "bar",
"will-be-overridden": "my-value",
}))
assert.Equal(t, m.Applications[1].Get("name"), "my-app")
env := generic.NewMap(m.Applications[1].Get("env"))
assert.Equal(t, env.Get("will-be-overridden"), "my-value")
assert.Equal(t, env.Get("foo"), "bar")
services := m.Applications[1].Get("services")
assert.Equal(t, services, []string{"base-service", "foo-service"})
}
开发者ID:nsnt,项目名称:cli,代码行数:20,代码来源:manifest_disk_repository_test.go
示例14: testManifestWithAbsolutePathOnWindows
func testManifestWithAbsolutePathOnWindows() {
m, errs := manifest.NewManifest(`C:\some\path`, generic.NewMap(map[interface{}]interface{}{
"applications": []interface{}{
map[interface{}]interface{}{
"path": `C:\another\path`,
},
},
}))
Expect(errs).To(BeEmpty())
Expect(*m.Applications[0].Path).To(Equal(`C:\another\path`))
}
开发者ID:knolleary,项目名称:cli,代码行数:12,代码来源:manifest_test.go
示例15: testManifestWithAbsolutePathOnPosix
func testManifestWithAbsolutePathOnPosix() {
m, errs := manifest.NewManifest("/some/path", generic.NewMap(map[interface{}]interface{}{
"applications": []interface{}{
map[interface{}]interface{}{
"path": "/another/path-segment",
},
},
}))
Expect(errs).To(BeEmpty())
Expect(*m.Applications[0].Path).To(Equal("/another/path-segment"))
}
开发者ID:knolleary,项目名称:cli,代码行数:12,代码来源:manifest_test.go
示例16: 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
示例17: TestParsingManifestWithNullCommand
func TestParsingManifestWithNullCommand(t *testing.T) {
m, err := manifest.NewManifest(generic.NewMap(map[string]interface{}{
"applications": []interface{}{
map[string]interface{}{
"command": nil,
},
},
}))
assert.NoError(t, err)
assert.Equal(t, m.Applications[0].Get("command"), "")
}
开发者ID:nsnt,项目名称:cli,代码行数:12,代码来源:manifest_test.go
示例18: envVarOrEmptyMap
func envVarOrEmptyMap(yamlMap generic.Map, errs *[]error) *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.NewWithFmt("Expected environment variable %s to have a string value, but it was a %T.", key, value))
}
})
return &result
default:
*errs = append(*errs, errors.NewWithFmt("Expected %s to be a set of key => value, but it was a %T.", key, envVars))
return nil
}
}
开发者ID:julz,项目名称:cli,代码行数:40,代码来源:manifest.go
示例19: manifestWithServicesAndEnv
func manifestWithServicesAndEnv() *manifest.Manifest {
return &manifest.Manifest{
Data: generic.NewMap(map[interface{}]interface{}{
"applications": []interface{}{
generic.NewMap(map[interface{}]interface{}{
"name": "app1",
"services": []interface{}{"app1-service", "global-service"},
"env": generic.NewMap(map[interface{}]interface{}{
"SOMETHING": "definitely-something",
}),
}),
generic.NewMap(map[interface{}]interface{}{
"name": "app2",
"services": []interface{}{"app2-service", "global-service"},
"env": generic.NewMap(map[interface{}]interface{}{
"SOMETHING": "nothing",
}),
}),
},
}),
}
}
开发者ID:juggernaut,项目名称:cli,代码行数:22,代码来源:push_test.go
示例20: singleAppManifest
func singleAppManifest() *manifest.Manifest {
return &manifest.Manifest{
Applications: []cf.AppParams{
cf.NewAppParams(generic.NewMap(map[interface{}]interface{}{
"name": "manifest-app-name",
"memory": uint64(128),
"instances": 1,
"host": "manifest-host",
"domain": "manifest-example.com",
"stack": "custom-stack",
"timeout": uint64(360),
"buildpack": "some-buildpack",
"command": `JAVA_HOME=$PWD/.openjdk JAVA_OPTS="-Xss995K" ./bin/start.sh run`,
"path": "../../fixtures/example-app",
"env": generic.NewMap(map[string]interface{}{
"FOO": "baz",
"PATH": "/u/apps/my-app/bin",
}),
})),
},
}
}
开发者ID:nsnt,项目名称:cli,代码行数:22,代码来源:push_test.go
注:本文中的generic.NewMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论