【发布时间】:2021-12-25 16:03:13
【问题描述】:
我有 config.yml 文件:
vcenter:
connection: https
hostname: vcenter.mydomain.lan
username: readonlyauto@vsphere.local
password: mypasspord
port: 443
EsxiExcludeDatastores:
- datastore1
- datastore2
EsxiExcludeDatastores2:
datastores:
- datastore1
- datastore2
我正在尝试用“gopkg.in/yaml.v2”解析它
我创建了结构:
type FileConfig struct {
Vcenter struct {
ConnectionType string `yaml:"connection"`
Hostname string `yaml:"hostname"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Port int `yaml:"port"`
} `yaml:"vcenter"`
EsxiExcludeDatastores struct {
Datastores []string `yaml:"EsxiExcludeDatastores"`
}
EsxiExcludeDatastores2 struct {
Datastores []string `yaml:"datastores"`
} `yaml:"EsxiExcludeDatastores2"`
}
var AppConfig FileConfig
解析后,我打印结果:
fmt.Println("Num of EsxiExcludeDatastores.Datastores = ", len(AppConfig.EsxiExcludeDatastores.Datastores))
fmt.Println("Num of EsxiExcludeDatastores2.Datastores = ", len(AppConfig.EsxiExcludeDatastores2.Datastores))
Num of EsxiExcludeDatastores.Datastores = 0
Num of EsxiExcludeDatastores2.Datastores = 2
你能帮我吗,我在 EsxiExcludeDatastores 结构中做错了什么?如您所见,使用 EsxiExcludeDatastores2 一切正常,但 EsxiExcludeDatastores 为空。
我尝试以不同的方式做到这一点,但没有结果......
【问题讨论】: