I want to update a YAML file dynamically via an HTTP POST request. I don't want to use reflection. Is there any other option to update an yaml files?
yaml File
name: John Doe
address: myStreet 10
counter: 10
calorie: 1000
type person struct {
Name string
Address string
Counter int
Calorie int
}
var dat = `{"counter": 10, "calorie": 500 }`
func main() {
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalln(err)
}
err = yaml.Unmarshal(yamlFile, &p2)
if err != nil {
log.Fatalln(err)
}
var p = &person{}
err := json.Unmarshal([]byte(dat), p)
if err != nil {
log.Fatalln(err)
}
}