Created
June 15, 2015 04:21
-
-
Save suntong/74c85d15b19ef4b14b0e to your computer and use it in GitHub Desktop.
Yaml Example
This file contains hidden or 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" | |
"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