yaml

package module
v0.0.0-...-b59ddd0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: MIT Imports: 8 Imported by: 0

README

yaml

A quick and dirty YAML parser in Go, with no external dependencies.

This library is not intended to embrace all features of YAML, just a large enough subset to be used for JSON <-> YAML conversions.

Usage

go get github.com/boynton/yaml

In your program, the decoded data looks like generic json data, objects are map[string]interface{}, arrays are []interface{}, and strings, numbers, and bools map to the standard types.

import "github.com/boynton/yaml"

From a file:

yamlFilename := "test.yml"
data, err := yaml.DecodeFile(yamlFilename)

From a byte array:

yamlBytes, _ := ioutil.ReadFile(filename)
data, err := yaml.DecodeBytes(yamlBytes)

From a string:

yamlString, _ := "one:\n    foo: This is a test\n    bar: 23"
data, err := yaml.DecodeString(yamlString)

From a reader:

data, err := yaml.Decode(strings.NewReader(yamlString))

To encode:

yamlString, err := yaml.Encode(data)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(in io.Reader) (map[string]interface{}, error)

func DecodeBytes

func DecodeBytes(in []byte) (map[string]interface{}, error)

func DecodeFile

func DecodeFile(filename string) (map[string]interface{}, error)

func DecodeString

func DecodeString(in string) (map[string]interface{}, error)

func Encode

func Encode(obj interface{}) (string, error)

Types

type DataDecoder

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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