1
0
mirror of https://github.com/Luzifer/promcertcheck.git synced 2024-09-20 01:42:56 +00:00
promcertcheck/vendor/gopkg.in/yaml.v2/example_embedded_test.go
Knut Ahlers 328cc40d38
Switch to dep for dependency managment, update deps
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-11-05 16:06:22 +01:00

42 lines
749 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.Fatal("cannot unmarshal data: %v", err)
}
fmt.Println(b.A)
fmt.Println(b.B)
// Output:
// a string from struct A
// a string from struct B
}