title: GoLang Redis : Map & Slice
body: <p>I'm using GoLang to get a data from redis hash and then map into a struct.</p>
  
  <pre><code>type Person struct {
      ID         string       `json:"id"`
      FirstName  string       `json:"firstName"`
      LastName   string       `json:"lastName"`
      Filters    interface{}  `json:"filters"`
      Type       string       `json:"type"`
  }
  </code></pre>
  
  <p>In Redis, a hash field contains a stringified JSON.</p>
  
  <blockquote>
    <p>HGET hashname fieldname </p>
  </blockquote>
  
  <p>Above returns a stringified JSON.</p>
  
  <p>Now "filters" key can be array or map based on the type (That's why I defined Filters type as interface in struct).<br>
  I marshall the JSON like below:</p>
  
  <pre><code>var p Person
  content, err := redis.HGet("hashName", "id").Result()
  _ = json.Unmarshal([]byte(content), &amp;p)
  </code></pre>
  
  <p>Now I have to loop over filters like below but this is giving error that <strong><em>cannot range over p.Filters (type interface {})</em></strong> (I understand why this error is coming)</p>
  
  <pre><code>for _, filter := range p.Filters {
    fmt.Println(filter)
  }
  </code></pre>
  
  <p>Is there any way we can handle this situation?</p>
  
  <p>Thanks,<br>
  Shashank</p>