...
Source file
src/gopkg.in/yaml.v2/example_embedded_test.go
1 package yaml_test
2
3 import (
4 "fmt"
5 "log"
6
7 "gopkg.in/yaml.v2"
8 )
9
10
11
12
13 type StructA struct {
14 A string `yaml:"a"`
15 }
16
17 type StructB struct {
18
19
20 StructA `yaml:",inline"`
21 B string `yaml:"b"`
22 }
23
24 var data = `
25 a: a string from struct A
26 b: a string from struct B
27 `
28
29 func ExampleUnmarshal_embedded() {
30 var b StructB
31
32 err := yaml.Unmarshal([]byte(data), &b)
33 if err != nil {
34 log.Fatalf("cannot unmarshal data: %v", err)
35 }
36 fmt.Println(b.A)
37 fmt.Println(b.B)
38
39
40
41 }
42
View as plain text