title: looping over struct and accessing array in golang
body: <p>My issue is</p>
  <ol>
  <li>I want to be able to loop over each server and within that loop, loop over UsageData</li>
  <li>My current loop gives me an error about ranging over assets not sure why</li>
  <li>I cant access assets.Server.UsageData</li>
  </ol>
  <p>Here is my code : <a href="https://go.dev/play/p/ttNVW5_Q4Ys" rel="nofollow noreferrer">https://go.dev/play/p/ttNVW5_Q4Ys</a></p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
  )
  
  type Asset struct {
      Server struct {
          Host string `json:&quot;host&quot;`
          Port string `json:&quot;port&quot;`
      } `json:&quot;server&quot;`
      Postgres struct {
          Host      string `json:&quot;host&quot;`
          User      string `json:&quot;user&quot;`
          Password  string `json:&quot;password&quot;`
          DB        string `json:&quot;db&quot;`
          UsageData []struct {
              Region string `json:&quot;Region&quot;`
              Mbps   int    `json:&quot;Mpbs&quot;`
          } `json:&quot;UsageData&quot;`
      } `json:&quot;database&quot;`
  }
  
  func main() {
      jsonConfig := []byte(`[
      {
          &quot;server&quot;:{
              &quot;host&quot;:&quot;serverA&quot;,
              &quot;port&quot;:&quot;8080&quot;},
          &quot;database&quot;:{
              &quot;host&quot;:&quot;serverA&quot;,
              &quot;user&quot;:&quot;db_user&quot;,
              &quot;password&quot;:&quot;supersecret&quot;,
              &quot;db&quot;:&quot;A_db&quot;,
              &quot;UsageData&quot;:[{&quot;Region&quot;:&quot;US&quot;,&quot;Mbps&quot;:100}, {&quot;Region&quot;:&quot;EU&quot;,&quot;Mbps&quot;:140}]
          }
      },
      {
          &quot;server&quot;:{
              &quot;host&quot;:&quot;serverB&quot;,
              &quot;port&quot;:&quot;8383&quot;},
          &quot;database&quot;:{
              &quot;host&quot;:&quot;serverB&quot;,
              &quot;user&quot;:&quot;db_user2&quot;,
              &quot;password&quot;:&quot;acbd123&quot;,
              &quot;db&quot;:&quot;B_db&quot;,
              &quot;UsageData&quot;:[{&quot;Region&quot;:&quot;US&quot;,&quot;Mbps&quot;:58}, {&quot;Region&quot;:&quot;EU&quot;,&quot;Mbps&quot;:250}]
          }   
      }
  ]`)
      var assets []Asset
      err := json.Unmarshal(jsonConfig, &amp;assets)
      if err != nil {
          panic(err)
      }
      fmt.Printf(&quot;Assets: %+v\n&quot;, assets)
      //fmt.Printf(&quot;Config: %+v\n&quot;, assets.Server.Host)
      //fmt.Printf(&quot;Config: %+v\n&quot;, assets.database.UsageData)
      //fmt.Printf(&quot;Config: %+v\n&quot;, assets.Server.UsageData)
  
      for _, asset := range assets {
          fmt.Printf(&quot;%v\n&quot;, asset)
          //for _, Usage := range assets.UsageData {
          //  fmt.Printf(&quot;%v\n&quot;,Usage)
          //}
      }
  }
  </code></pre>
  <p>** Code with the correct answer, I was calling the nested struct incorrectly**</p>
  <p><a href="https://go.dev/play/p/tEbA405WWbC" rel="nofollow noreferrer">https://go.dev/play/p/tEbA405WWbC</a></p>