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


Golang candiedyaml.Unmarshal函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/candiedyaml.Unmarshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: Match

func (matcher *MatchYAMLMatcher) Match(actual interface{}) (success bool, err error) {
	actualString, expectedString, err := matcher.prettyPrint(actual)
	if err != nil {
		return false, err
	}

	var aval interface{}
	var eval interface{}

	// this is guarded by prettyPrint
	candiedyaml.Unmarshal([]byte(actualString), &aval)
	candiedyaml.Unmarshal([]byte(expectedString), &eval)

	return reflect.DeepEqual(aval, eval), nil
}
开发者ID:liuyuns,项目名称:consul-release,代码行数:15,代码来源:match_yaml.go

示例2: TestSliceOrMapYaml

func TestSliceOrMapYaml(t *testing.T) {
	str := `{foos: [bar=baz, far=faz]}`

	s := StructSliceorMap{}
	yaml.Unmarshal([]byte(str), &s)

	assert.Equal(t, SliceorMap{"bar": "baz", "far": "faz"}, s.Foos)

	d, err := yaml.Marshal(&s)
	assert.Nil(t, err)

	s2 := StructSliceorMap{}
	yaml.Unmarshal(d, &s2)

	assert.Equal(t, SliceorMap{"bar": "baz", "far": "faz"}, s2.Foos)
}
开发者ID:haj,项目名称:kompose,代码行数:16,代码来源:types_yaml_test.go

示例3: readMetadata

func readMetadata() datasource.Metadata {
	metadata := datasource.Metadata{}
	if metaDataBytes, err := ioutil.ReadFile(MetaDataFile); err == nil {
		yaml.Unmarshal(metaDataBytes, &metadata)
	}
	return metadata
}
开发者ID:pirater,项目名称:os,代码行数:7,代码来源:disk.go

示例4: ResolveManifestVersions

func (c Client) ResolveManifestVersions(yaml []byte) ([]byte, error) {
	m := manifest{}
	err := candiedyaml.Unmarshal(yaml, &m)
	if err != nil {
		return nil, err
	}

	for i, r := range m.Releases {
		if r.Version == "latest" {
			release, err := c.Release(r.Name)
			if err != nil {
				return nil, err
			}
			r.Version = release.Latest()
			m.Releases[i] = r
		}
	}

	for i, pool := range m.ResourcePools {
		if pool.Stemcell.Version == "latest" {
			stemcell, err := c.Stemcell(pool.Stemcell.Name)
			if err != nil {
				return nil, err
			}
			pool.Stemcell.Version = stemcell.Latest()
			m.ResourcePools[i] = pool
		}
	}

	return candiedyaml.Marshal(m)
}
开发者ID:liuyuns,项目名称:consul-release,代码行数:31,代码来源:client.go

示例5: Initialize

func (cfg *Config) Initialize(file []byte, authDisabled bool) error {
	err := candiedyaml.Unmarshal(file, &cfg)
	if err != nil {
		return err
	}

	if cfg.LogGuid == "" {
		return errors.New("No log_guid specified")
	}

	if !authDisabled && cfg.OAuth.TokenEndpoint == "" {
		return errors.New("No token endpoint specified")
	}

	if !authDisabled && cfg.OAuth.TokenEndpoint != "" && cfg.OAuth.Port == -1 {
		return errors.New("Routing API requires TLS enabled to get OAuth token")
	}

	err = cfg.process()

	if err != nil {
		return err
	}

	return nil
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:26,代码来源:config.go

示例6: getServices

func getServices(urls []string, key string) ([]string, error) {
	result := []string{}

	for _, url := range urls {
		indexUrl := fmt.Sprintf("%s/index.yml", url)
		content, err := LoadResource(indexUrl, true)
		if err != nil {
			log.Errorf("Failed to load %s: %v", indexUrl, err)
			continue
		}

		services := make(map[string][]string)
		err = yaml.Unmarshal(content, &services)
		if err != nil {
			log.Errorf("Failed to unmarshal %s: %v", indexUrl, err)
			continue
		}

		if list, ok := services[key]; ok {
			result = append(result, list...)
		}
	}

	return result, nil
}
开发者ID:coderjoe,项目名称:os,代码行数:25,代码来源:network.go

示例7: mergeProject

func mergeProject(p *Project, bytes []byte) (map[string]*ServiceConfig, error) {
	configs := make(map[string]*ServiceConfig)

	datas := make(rawServiceMap)
	if err := yaml.Unmarshal(bytes, &datas); err != nil {
		return nil, err
	}

	if err := interpolate(p.context.EnvironmentLookup, &datas); err != nil {
		return nil, err
	}

	for name, data := range datas {
		data, err := parse(p.context.ConfigLookup, p.context.EnvironmentLookup, p.File, data, datas)
		if err != nil {
			logrus.Errorf("Failed to parse service %s: %v", name, err)
			return nil, err
		}

		datas[name] = data
	}

	if err := utils.Convert(datas, &configs); err != nil {
		return nil, err
	}

	adjustValues(configs)
	return configs, nil
}
开发者ID:pirater,项目名称:os,代码行数:29,代码来源:merge.go

示例8: TestStringorsliceYaml

func TestStringorsliceYaml(t *testing.T) {
	str := `{foo: [bar, baz]}`

	s := StructStringorslice{}
	yaml.Unmarshal([]byte(str), &s)

	assert.Equal(t, Stringorslice{"bar", "baz"}, s.Foo)

	d, err := yaml.Marshal(&s)
	assert.Nil(t, err)

	s2 := StructStringorslice{}
	yaml.Unmarshal(d, &s2)

	assert.Equal(t, Stringorslice{"bar", "baz"}, s2.Foo)
}
开发者ID:haj,项目名称:kompose,代码行数:16,代码来源:types_yaml_test.go

示例9: FromYAML

func FromYAML(yaml []byte) (Manifest, error) {
	var m Manifest
	if err := candiedyaml.Unmarshal(yaml, &m); err != nil {
		return m, err
	}
	return m, nil
}
开发者ID:liuyuns,项目名称:consul-release,代码行数:7,代码来源:manifest.go

示例10: unmarshalOrReturnString

func unmarshalOrReturnString(value string) (result interface{}) {
	value = strings.Replace(value, "\n", magicString, -1)
	if err := yaml.Unmarshal([]byte(value), &result); err != nil {
		result = value
	}
	result = reverseReplacement(result)
	return
}
开发者ID:carriercomm,项目名称:os,代码行数:8,代码来源:data_funcs.go

示例11: TestUnmarshalCommand

func TestUnmarshalCommand(t *testing.T) {
	s := &StructCommand{}
	err := yaml.Unmarshal([]byte(sampleStructCommand), s)

	assert.Nil(t, err)
	assert.Equal(t, Command{"bash"}, s.Command)
	assert.Nil(t, s.Entrypoint)
	bytes, err := yaml.Marshal(s)
	assert.Nil(t, err)

	s2 := &StructCommand{}
	err = yaml.Unmarshal(bytes, s2)

	assert.Nil(t, err)
	assert.Equal(t, Command{"bash"}, s2.Command)
	assert.Nil(t, s2.Entrypoint)
}
开发者ID:haj,项目名称:kompose,代码行数:17,代码来源:types_yaml_test.go

示例12: TestUnmarshalEmptyCommand

func TestUnmarshalEmptyCommand(t *testing.T) {
	s := &StructCommand{}
	err := yaml.Unmarshal([]byte(sampleEmptyCommand), s)

	assert.Nil(t, err)
	assert.Nil(t, s.Command)

	bytes, err := yaml.Marshal(s)
	assert.Nil(t, err)
	assert.Equal(t, "{}", strings.TrimSpace(string(bytes)))

	s2 := &StructCommand{}
	err = yaml.Unmarshal(bytes, s2)

	assert.Nil(t, err)
	assert.Nil(t, s2.Command)
}
开发者ID:haj,项目名称:kompose,代码行数:17,代码来源:types_yaml_test.go

示例13: TestUnmarshalSlice

func TestUnmarshalSlice(t *testing.T) {
	expected := &structStringorslice{Foo: NewStringorslice("a", "b", "c")}
	b := []byte("foo: [a, b, c]\n")
	s := &structStringorslice{}
	err := yaml.Unmarshal(b, s)
	assert.Equal(t, expected, s)
	assert.Nil(t, err)
}
开发者ID:pirater,项目名称:os,代码行数:8,代码来源:yaml_test.go

示例14: TestUnmarshalEmpty

func TestUnmarshalEmpty(t *testing.T) {
	expected := &structStringorslice{Foo: NewStringorslice()}
	b := []byte("{}\n")
	s := &structStringorslice{}
	err := yaml.Unmarshal(b, s)
	assert.Equal(t, expected, s)
	assert.Nil(t, err)
}
开发者ID:pirater,项目名称:os,代码行数:8,代码来源:yaml_test.go

示例15: testInvalidInterpolatedConfig

func testInvalidInterpolatedConfig(t *testing.T, interpolatedConfig string) {
	interpolatedConfigBytes := []byte(interpolatedConfig)
	interpolatedData := make(RawServiceMap)
	yaml.Unmarshal(interpolatedConfigBytes, &interpolatedData)

	err := Interpolate(new(MockEnvironmentLookup), &interpolatedData)

	assert.NotNil(t, err)
}
开发者ID:datawolf,项目名称:libcompose,代码行数:9,代码来源:interpolation_test.go


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