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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -