woodpecker/vendor/github.com/cloudfoundry-incubator/candiedyaml
2016-04-16 00:51:05 -07:00
..
api.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
decode.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
emitter.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
encode.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
libyaml-LICENSE new yaml parser, runner 2016-04-16 00:51:05 -07:00
LICENSE new yaml parser, runner 2016-04-16 00:51:05 -07:00
parser.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
reader.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
README.md new yaml parser, runner 2016-04-16 00:51:05 -07:00
resolver.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
run_parser.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
scanner.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
tags.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
writer.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
yaml_definesh.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
yaml_privateh.go new yaml parser, runner 2016-04-16 00:51:05 -07:00
yamlh.go new yaml parser, runner 2016-04-16 00:51:05 -07:00

Build Status

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
}