Last active
June 20, 2016 22:17
-
-
Save chrsblck/04568b2c2daacd10b0cbc15dbfcc965f to your computer and use it in GitHub Desktop.
Read defs yaml
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" | |
"path/filepath" | |
"gopkg.in/yaml.v2" | |
) | |
type Config struct { | |
Types map[string]Owner | |
} | |
type Owner struct { | |
Owners map[string]Rule | |
} | |
type Rule struct { | |
Suffix string | |
Maxsize string | |
Maxpct string | |
} | |
func main() { | |
filename, _ := filepath.Abs("./defs.yaml") | |
yamlFile, err := ioutil.ReadFile(filename) | |
if err != nil { | |
panic(err) | |
} | |
var config Config | |
err = yaml.Unmarshal(yamlFile, &config) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("config: %+v\n", config) | |
fmt.Printf("Aviradef 1.0 maxpct is %q\n", config.Types["aviradef"].Owners["1.0"].Maxpct) | |
} | |
__DATA__ | |
types: | |
aviradef: | |
owners: | |
"1.0": | |
maxpct: 20 | |
maxsize: 15M | |
suffix: i | |
"2.0": | |
maxpct: 10 | |
maxsize: 20M | |
suffix: a | |
updatedef: | |
owners: | |
"9.0": | |
maxpct: 50 | |
maxsize: 100G | |
suffix: b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment