cri-o/vendor/github.com/cloudfoundry-incubator/candiedyaml
Antonio Murdaca d8ae7178e2 pull in containers/image deps
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-09-09 14:41:03 -07:00
..
.gitignore pull in containers/image deps 2016-09-09 14:41:03 -07:00
.travis.yml pull in containers/image deps 2016-09-09 14:41:03 -07:00
api.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
decode.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
emitter.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
encode.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
libyaml-LICENSE pull in containers/image deps 2016-09-09 14:41:03 -07:00
LICENSE pull in containers/image deps 2016-09-09 14:41:03 -07:00
parser.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
reader.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
README.md pull in containers/image deps 2016-09-09 14:41:03 -07:00
resolver.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
run_parser.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
scanner.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
tags.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
writer.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
yaml_definesh.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
yaml_privateh.go pull in containers/image deps 2016-09-09 14:41:03 -07:00
yamlh.go pull in containers/image deps 2016-09-09 14:41:03 -07:00

Build Status GoDoc

candiedyaml

YAML for Go

A YAML 1.1 parser with support for YAML 1.2 features

Usage

package myApp

import (
  "github.com/cloudfoundry-incubator/candiedyaml"
  "fmt"
  "os"
)

func main() {
  file, err := os.Open("path/to/some/file.yml")
  if err != nil {
    println("File does not exist:", err.Error())
    os.Exit(1)
  }
  defer file.Close()

  document := new(interface{})
  decoder := candiedyaml.NewDecoder(file)
  err = decoder.Decode(document)
  
  if err != nil {
    println("Failed to decode document:", err.Error())
  }
  
  println("parsed yml into interface:", fmt.Sprintf("%#v", document))
  
  fileToWrite, err := os.Create("path/to/some/new/file.yml")
  if err != nil {
    println("Failed to open file for writing:", err.Error())
    os.Exit(1)
  }
  defer fileToWrite.Close()

  encoder := candiedyaml.NewEncoder(fileToWrite)
  err = encoder.Encode(document)

  if err != nil {
    println("Failed to encode document:", err.Error())
    os.Exit(1)
  }
  
  return
}