Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Created August 22, 2013 00:25
Show Gist options
  • Save johnwesonga/6301897 to your computer and use it in GitHub Desktop.
Save johnwesonga/6301897 to your computer and use it in GitHub Desktop.
read yaml file in Go
username: admin
password: pass
package main
import (
"fmt"
"io/ioutil"
"launchpad.net/goyaml"
)
type Config struct {
Username string
Password string
}
var c Config
func main() {
file, err := ioutil.ReadFile("config.yaml")
if err != nil {
panic(err)
}
if err := goyaml.Unmarshal([]byte(file), &c); err != nil {
panic(err)
}
fmt.Printf("--- t:\n%v\n\n", c)
d, err := goyaml.Marshal(&c)
if err != nil {
panic(err)
}
fmt.Printf("--- t dump:\n%s\n\n", string(d))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment