Skip to content

Instantly share code, notes, and snippets.

@xorpaul
Created July 28, 2015 16:41
Show Gist options
  • Save xorpaul/fed389798039b51e28e5 to your computer and use it in GitHub Desktop.
Save xorpaul/fed389798039b51e28e5 to your computer and use it in GitHub Desktop.
Decode YAML in Go
---
cachedir: '/var/cache/g10k'

git:
  provider: 'rugged'
  private_key: '/root/coro'
  username: 'git'

sources:
  core:
    remote: 'https://github.com/puppet-community/puppet-corosync.git'
    basedir: '/var/data/g10k/core/'
    prefix: true
// ConfigSettings contains the key value pairs from the g10k config file
type ConfigSettings struct {
	CacheDir string `yaml:"cachedir"`
	Git      struct {
		PrivateKey string `yaml:"private_key"`
		Username   string
	}
	Sources map[string]Source
}

type Source struct {
	Remote  string
	Basedir string
	Prefix  bool
}

func main() {
       var config ConfigSettings
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	log.Printf("--- config:\n%v\n\n", config)

	for k, v := range config.Sources {
		log.Print(k)
		log.Print(v.Remote)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment