Josh Curl 50de80d09a Bump libcompose and its dependencies | 8 年之前 | |
---|---|---|
.. | ||
.gitignore | 9 年之前 | |
.travis.yml | 9 年之前 | |
LICENSE | 9 年之前 | |
README.md | 8 年之前 | |
api.go | 9 年之前 | |
decode.go | 9 年之前 | |
emitter.go | 8 年之前 | |
encode.go | 8 年之前 | |
libyaml-LICENSE | 9 年之前 | |
parser.go | 9 年之前 | |
reader.go | 9 年之前 | |
resolver.go | 8 年之前 | |
run_parser.go | 9 年之前 | |
scanner.go | 8 年之前 | |
tags.go | 8 年之前 | |
writer.go | 9 年之前 | |
yaml_definesh.go | 9 年之前 | |
yaml_privateh.go | 9 年之前 | |
yamlh.go | 9 年之前 |
YAML for Go
A YAML 1.1 parser with support for YAML 1.2 features
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
}