Files
weave-scope/vendor/gopkg.in/yaml.v2/example_embedded_test.go
Daniel Holbach 56f7db1821 vendor: update gopkg.in/yaml.v2 to latest upstream
yaml.v2 was relicensed under Apache 2.0 in 2016, as Scope is
  Apache 2.0, we want this too. A lot of other bugs were fixed
  in the code since then as well.

  fixes #3283
2018-08-14 15:08:15 +02:00

42 lines
712 B
Go

package yaml_test
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
// An example showing how to unmarshal embedded
// structs from YAML.
type StructA struct {
A string `yaml:"a"`
}
type StructB struct {
// Embedded structs are not treated as embedded in YAML by default. To do that,
// add the ",inline" annotation below
StructA `yaml:",inline"`
B string `yaml:"b"`
}
var data = `
a: a string from struct A
b: a string from struct B
`
func ExampleUnmarshal_embedded() {
var b StructB
err := yaml.Unmarshal([]byte(data), &b)
if err != nil {
log.Fatalf("cannot unmarshal data: %v", err)
}
fmt.Println(b.A)
fmt.Println(b.B)
// Output:
// a string from struct A
// a string from struct B
}