yaml

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2020 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToInterface

func ToInterface(reader io.Reader) (interface{}, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL