Skip to content

Instantly share code, notes, and snippets.

@suntong
Created June 15, 2015 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/74c85d15b19ef4b14b0e to your computer and use it in GitHub Desktop.
Save suntong/74c85d15b19ef4b14b0e to your computer and use it in GitHub Desktop.
Yaml Example
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
type Config struct {
Foo string
Bar []string
}
var data = `
foo: 1
bar:
- one
- two
- three
`
func main() {
var config Config
/*
filename := os.Args[1]
source, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
*/
source := []byte(data)
err := yaml.Unmarshal(source, &config)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("Value: %#v\n", config.Bar[0])
fmt.Printf("--- config:\n%v\n\n", config)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment