golang如何解析每个HCL字典项?
我尝试使用golang如何解析每个HCL字典项?,go,hcl,Go,Hcl,我尝试使用golang解析HCL配置,但它不起作用 type cfg_dict struct { name string `hcl:",key"` type string `hcl:"type"` } type hcl_config struct { config_items cfg_dict `hcl:"config"` } func main() { hcl_example = `conf
golang
解析HCL配置,但它不起作用
type cfg_dict struct {
name string `hcl:",key"`
type string `hcl:"type"`
}
type hcl_config struct {
config_items cfg_dict `hcl:"config"`
}
func main() {
hcl_example = `config "cfg1" {
type = "string"
}`
hcl_opts := &hcl_config{}
hcl_tree, err := hcl.Parse(hcl_example)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := hcl.DecodeObject(&hcl_opts, hcl_tree); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(hcl_opts)
}
当我试图在构建后运行此测试代码时,它显示空值
&{[]}
有什么问题需要解决吗?导出结构字段;将字段名的第一个字母改为大写。谢谢,这对我很有用。