simpleyaml

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: BSD-3-Clause Imports: 2 Imported by: 58

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

Documentation

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)

GetArraySize 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)

GetMapKeys 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

IsFound Check if the given branch was found

func (*Yaml) IsMap

func (y *Yaml) IsMap() bool

IsMap 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`

Directories

Path Synopsis
helper

Jump to

Keyboard shortcuts

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