README

simpleyaml

a Go package to interact with arbitrary YAML, similar as go-simplejson.

GoDoc Build Status

INSTALL
$ go get -u -v github.com/smallfish/simpleyaml
EXAMPLE
var data = []byte(`
name: smallfish
age: 99
float: 3.14159
bool: true
emails:
   - xxx@xx.com
   - yyy@yy.com
bb:
    cc:
        dd:
            - 111
            - 222
            - 333
        ee: aaa
`)

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

name, err := y.Get("name").String()
if err != nil {
        // ERROR
}
fmt.Println("name:", name)

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

END

Expand ▾ Collapse ▴

Documentation

Overview

    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

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Yaml

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

    func NewYaml

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

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

      func (*Yaml) Array

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

        Array type asserts to an `array`

        func (*Yaml) Bool

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

          Bool type asserts to `bool`

          func (*Yaml) Float

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

          func (*Yaml) Get

          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

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

              return the size of array

              func (*Yaml) GetIndex

              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

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

                  Get all the keys of the map

                  func (*Yaml) GetPath

                  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

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

                      Int type asserts to `int`

                      func (*Yaml) IsArray

                      func (y *Yaml) IsArray() bool

                      func (*Yaml) IsFound

                      func (y *Yaml) IsFound() bool

                        Check if the given branch was found

                        func (*Yaml) IsMap

                        func (y *Yaml) IsMap() bool

                          Check if it is a map

                          func (*Yaml) Map

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

                            Map type asserts to `map`

                            func (*Yaml) String

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

                              String type asserts to `string`

                              Source Files

                              Directories

                              Path Synopsis
                              helper