我在读取 YAML 文件时遇到问题。我认为这是文件结构中的一些东西,但我不知道是什么。
YAML 文件:
conf:
hits:5
time:5000000
代码:
type conf struct {
hits int64 `yaml:"hits"`
time int64 `yaml:"time"`
}
func (c *conf) getConf() *conf {
yamlFile, err := ioutil.ReadFile("conf.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return c
}
原文由 MIkCode 发布,翻译遵循 CC BY-SA 4.0 许可协议
你的 yaml 文件必须是
你的代码应该是这样的:
主要错误是您的结构的大写字母。