Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToInterface ¶
ToInterface unmarshalls YAML reader to a "generic" interface
Example (Empty) ¶
package main
import (
"fmt"
"os"
"reflect"
"strings"
"github.com/VirtusLab/go-extended/pkg/yaml"
)
func main() {
y := ``
data, err := yaml.ToInterface(strings.NewReader(y))
if err != nil {
_, _ = fmt.Fprint(os.Stderr, err)
}
fmt.Println(data)
fmt.Println(reflect.TypeOf(data))
fmt.Println(reflect.ValueOf(data).Kind())
}
Output: map[] map[string]interface {} map
Example (Multi) ¶
package main
import (
"fmt"
"os"
"reflect"
"strings"
"github.com/VirtusLab/go-extended/pkg/yaml"
)
func main() {
y := `---
data:
en: "Hello World!"
---
data:
pl: "Witaj Świecie!"
`
data, err := yaml.ToInterface(strings.NewReader(y))
if err != nil {
_, _ = fmt.Fprint(os.Stderr, err)
}
fmt.Println(data)
fmt.Println(reflect.TypeOf(data))
fmt.Println(reflect.ValueOf(data).Kind())
}
Output: [map[data:map[en:Hello World!]] map[data:map[pl:Witaj Świecie!]]] []interface {} slice
Example (Simple) ¶
package main
import (
"fmt"
"os"
"reflect"
"strings"
"github.com/VirtusLab/go-extended/pkg/yaml"
)
func main() {
y := `---
welcome:
message:
- "Good Morning"
- "Hello World!"
`
data, err := yaml.ToInterface(strings.NewReader(y))
if err != nil {
_, _ = fmt.Fprint(os.Stderr, err)
}
fmt.Println(data)
fmt.Println(reflect.TypeOf(data))
fmt.Println(reflect.ValueOf(data).Kind())
}
Output: map[welcome:map[message:[Good Morning Hello World!]]] map[string]interface {} map
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.