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


Golang generic.NewMap函數代碼示例

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


在下文中一共展示了NewMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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