github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fit/bug_yml-config/spike.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/grantbow/yaml" 6 ) 7 8 type person struct { 9 // location of root dir and .bug.yml 10 BugDir string `json:"BugDir"` 11 // overrides auto-find root dir 12 // overridden by PMIT environment variable 13 PMIT string `json:"PMIT"` 14 // new bug Description text template 15 DefaultDescriptionFile string `json:"DefaultDescriptionFile"` 16 // saves raw json files of import 17 ImportXmlDump bool `json:"ImportXmlDump"` 18 } 19 20 func main() { 21 // Marshal a person struct to YAML. 22 p := person{"goodbugdir", "pain", "path", true} 23 y, err := yaml.Marshal(p) 24 if err != nil { 25 fmt.Printf("err: %v\n", err) 26 return 27 } 28 fmt.Println(string(y)) 29 /* Output: 30 age: 30 31 name: John 32 */ 33 34 // Unmarshal the YAML back into a person struct. 35 var p2 person 36 err = yaml.Unmarshal(y, &p2) 37 if err != nil { 38 fmt.Printf("err: %v\n", err) 39 return 40 } 41 fmt.Println(p2) 42 /* Output: 43 {John 30} 44 */ 45 }