本文整理汇总了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
}
示例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)
}
示例3: readMetadata
func readMetadata() datasource.Metadata {
metadata := datasource.Metadata{}
if metaDataBytes, err := ioutil.ReadFile(MetaDataFile); err == nil {
yaml.Unmarshal(metaDataBytes, &metadata)
}
return metadata
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}