1package yaml_test
2
3import (
4	"fmt"
5	"log"
6
7        "gopkg.in/yaml.v2"
8)
9
10// An example showing how to unmarshal embedded
11// structs from YAML.
12
13type StructA struct {
14	A string `yaml:"a"`
15}
16
17type StructB struct {
18	// Embedded structs are not treated as embedded in YAML by default. To do that,
19	// add the ",inline" annotation below
20	StructA   `yaml:",inline"`
21	B string `yaml:"b"`
22}
23
24var data = `
25a: a string from struct A
26b: a string from struct B
27`
28
29func ExampleUnmarshal_embedded() {
30	var b StructB
31
32	err := yaml.Unmarshal([]byte(data), &b)
33	if err != nil {
34		log.Fatal("cannot unmarshal data: %v", err)
35	}
36        fmt.Println(b.A)
37        fmt.Println(b.B)
38        // Output:
39        // a string from struct A
40        // a string from struct B
41}
42