dictionary - How to range over nested struct in golang? -
i new golang: these defined struct:
type name map[string]info type info struct { addresses string `json:"addresses"` host map[string]server `json:"host"` } type server struct { ipaddress string `json:"ip"` status string `json:"status"` } var result name
after unmarshalling json get:
result = [ user1:{ 192.168.98.0/26 map[ xx.user1.domain.com:{192.168.98.1 good} xx.user1.domain.com:{192.168.98.3 good} xx.user1.domain.com:{192.168.98.4 bad} ] } user2: { 192.168.99.0/26 map[ xx.user2.domain.com:{192.168.99.1 good} ] } ]
how range on json ipaddress has status=="good" particular user ?
i trying way:
j , _ := range result["user1"].servers { if := result["user1"].servers[j]); == "good" { //problem here not sure how further scan ip , status //do
}
} }
i think want:
for _ , := range result { _, j := range i.host { if j.status == "good" { server := j.ip } } }
Comments
Post a Comment