Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created July 30, 2015 19:35
Show Gist options
  • Save squeedee/1f309f8264c97cc672fe to your computer and use it in GitHub Desktop.
Save squeedee/1f309f8264c97cc672fe to your computer and use it in GitHub Desktop.
Candied Yaml doesn't support merge.
---
services:
- acceptance-db
env:
RAILS_ENV: acceptance
application-types:
web: &WEB
mem: 2G
disk: 2G
applications:
-
name: blue
<<: *WEB
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/cloudfoundry-incubator/candiedyaml"
"github.com/cloudfoundry/cli/generic"
)
func parseManifest(path string) (yamlMap generic.Map) {
file, err := os.Open(filepath.Clean(path))
if err != nil {
fmt.Println("Could not open")
return
}
defer file.Close()
decoder := candiedyaml.NewDecoder(file)
yamlMap = generic.NewMap()
err = decoder.Decode(yamlMap)
if err != nil {
return
}
if !generic.IsMappable(yamlMap) {
fmt.Println("Invalid manifest - not a map")
return
}
return
}
func main() {
mapp := parseManifest("./manifest.yml")
fmt.Println(mapp)
}
@squeedee
Copy link
Author

○ → go run test.go
map[services:[acceptance-db] env:map[RAILS_ENV:acceptance] application-types:map[web:map[mem:2G disk:2G]] applications:[map[name:blue <<:map[disk:2G mem:2G]]]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment