Created
August 22, 2013 00:25
-
-
Save johnwesonga/6301897 to your computer and use it in GitHub Desktop.
read yaml file in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
username: admin | |
password: pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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