代码:
type HostSystemIdentificationInfo []struct {
IdentiferValue string `xml:"identifierValue"`
IdentiferType struct {
Label string `xml:"label"`
Summary string `xml:"summary"`
Key string `xml:"key"`
} `xml:"identifierType"`
}
func vsphereHost(v *vsphere.Vsphere, md *opentsdb.MultiDataPoint) error {
res, err := v.Info("HostSystem", []string{
"name",
"summary.hardware.cpuMhz",
"summary.hardware.memorySize", // bytes
"summary.hardware.numCpuCores",
"summary.hardware.numCpuCores",
"summary.quickStats.overallCpuUsage", // MHz
"summary.quickStats.overallMemoryUsage", // MB
"summary.hardware.otherIdentifyingInfo",
"summary.hardware.model",
})
for _, r := range res {
for _, p := range r.Props {
if p.Name == "summary.hardware.otherIdentifyingInfo" {
var t HostSystemIdentificationInfo
fmt.Println(p.Val.Inner)
err := xml.Unmarshal([]byte(p.Val.Inner), &t)
if err != nil {
return err
}
fmt.Println(t)
}
}
}
所以问题是当我解组时,我只在结果中得到 HostSystemIdentification 结构之一,而不是完整数组。我该如何解决?
这是一个问题减少的去游乐场:http : //play.golang.org/p/5uRJ6Eu8jK
茅侃侃
相关分类