I'm trying to figure out how to organize my Golang structs to store my yaml file. I think I'm having a bit of a problem with the nested maps. I'm trying to get this yaml file to be stored in something like {statCategory:{CatOne:{featD:{description:amazing, unit:nil}}}
.
I'm currently using yaml "gopkg.in/yaml.v2"
for parsing yaml.
Below is the yaml file that I'm trying to parse.
stat:
statCategory:
CatOne:
featD:
description: amazing
unit: nil
featH:
description: not amazing
unit: nil
CatTwo:
featA:
description: hello
unit: ms
featB:
description: something
unit: ms
featC:
description: another description
unit: ms
I've tried to use the struct below, but it's seem to only kinda work.
type yamlStatDAO struct {
Stat statCategory `yaml:"stat"`
}
type statCategory struct {
StatCat map[string]map[string]statInfo `yaml:"statCategory"`
}
type statInfo struct {
description string `yaml:"description"`
unit string `yaml:"unit"`
}
But I only end up with {statCategory:{CatOne:{featD:{}}}
. If I can't figure this out, I might just restructure my yaml file.
EDIT: seems like the solution was just to capitalize description and unit.
type statInfo struct {
Description string `yaml:"description"`
Unit string `yaml:"unit"`
}
Thanks to Alexander Maru from the comments.