simpleyaml: github.com/smallfish/simpleyaml Index | Files | Directories

package simpleyaml

import "github.com/smallfish/simpleyaml"

a Go package to interact with arbitrary YAML.

Example:

var data = []byte(`
name: smallfish
age: 99
bool: true
bb:
    cc:
        dd:
            - 111
            - 222
            - 333
`

y, err := simpleyaml.NewYaml(data)
if err != nil {
	// ERROR
}

if v, err := y.Get("name").String(); err == nil {
	fmt.Println("value:", v)
}

// y.Get("age").Int()
// y.Get("bool").Bool()
// y.Get("bb").Get("cc").Get("dd").Array()
// y.Get("bb").Get("cc").Get("dd").GetIndex(1).Int()
// y.GetPath("bb", "cc", "ee").String()

Index

Package Files

simpleyaml.go

type Yaml Uses

type Yaml struct {
    // contains filtered or unexported fields
}

func NewYaml Uses

func NewYaml(body []byte) (*Yaml, error)

NewYaml returns a pointer to a new `Yaml` object after unmarshaling `body` bytes

func (*Yaml) Array Uses

func (y *Yaml) Array() ([]interface{}, error)

Array type asserts to an `array`

func (*Yaml) Bool Uses

func (y *Yaml) Bool() (bool, error)

Bool type asserts to `bool`

func (*Yaml) Float Uses

func (y *Yaml) Float() (float64, error)

func (*Yaml) Get Uses

func (y *Yaml) Get(key interface{}) *Yaml

Get returns a pointer to a new `Yaml` object for `key` in its `map` representation

Example:

y.Get("xx").Get("yy").Int()

func (*Yaml) GetArraySize Uses

func (y *Yaml) GetArraySize() (int, error)

return the size of array

func (*Yaml) GetIndex Uses

func (y *Yaml) GetIndex(index int) *Yaml

GetIndex returns a pointer to a new `Yaml` object. for `index` in its `array` representation

Example:

y.Get("xx").GetIndex(1).String()

func (*Yaml) GetMapKeys Uses

func (y *Yaml) GetMapKeys() ([]string, error)

Get all the keys of the map

func (*Yaml) GetPath Uses

func (y *Yaml) GetPath(branch ...interface{}) *Yaml

GetPath searches for the item as specified by the branch

Example:

y.GetPath("bb", "cc").Int()

func (*Yaml) Int Uses

func (y *Yaml) Int() (int, error)

Int type asserts to `int`

func (*Yaml) IsArray Uses

func (y *Yaml) IsArray() bool

func (*Yaml) IsFound Uses

func (y *Yaml) IsFound() bool

Check if the given branch was found

func (*Yaml) IsMap Uses

func (y *Yaml) IsMap() bool

Check if it is a map

func (*Yaml) Map Uses

func (y *Yaml) Map() (map[interface{}]interface{}, error)

Map type asserts to `map`

func (*Yaml) String Uses

func (y *Yaml) String() (string, error)

String type asserts to `string`

Directories

PathSynopsis
helper/util

Package simpleyaml imports 2 packages (graph) and is imported by 12 packages. Updated 2018-01-04. Refresh now. Tools for package owners.