open-vault/vendor/github.com/cloudfoundry-incubator/candiedyaml
Jeff Mitchell 6ef30efae6 Bump deps.
2016-05-02 20:11:05 -04:00
..
.gitignore Update godeps 2016-03-10 22:50:50 -05:00
.travis.yml Update godeps 2016-03-10 22:50:50 -05:00
api.go Update godeps 2016-03-10 22:50:50 -05:00
decode.go Update vendoring 2016-04-26 00:18:04 +00:00
emitter.go Update vendoring 2016-04-26 00:18:04 +00:00
encode.go Update godeps 2016-03-10 22:50:50 -05:00
libyaml-LICENSE Update godeps 2016-03-10 22:50:50 -05:00
LICENSE Update vendoring 2016-04-26 00:18:04 +00:00
parser.go Update godeps 2016-03-10 22:50:50 -05:00
reader.go Update godeps 2016-03-10 22:50:50 -05:00
README.md Bump deps. 2016-05-02 20:11:05 -04:00
resolver.go Update godeps 2016-03-10 22:50:50 -05:00
run_parser.go Update godeps 2016-03-10 22:50:50 -05:00
scanner.go Update vendoring 2016-04-26 00:18:04 +00:00
tags.go Update godeps 2016-03-10 22:50:50 -05:00
writer.go Update godeps 2016-03-10 22:50:50 -05:00
yaml_definesh.go Update godeps 2016-03-10 22:50:50 -05:00
yaml_privateh.go Update godeps 2016-03-10 22:50:50 -05:00
yamlh.go Update godeps 2016-03-10 22:50:50 -05: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
}