title: Cannot Range Over List Type Interface {} In Function Using Go
body: <p>Cannot Range Over List Type Interface {} In Function Using Go.</p>
  
  <ul>
  <li>for me is important then i execute for in a function.</li>
  </ul>
  
  <p>How can fix?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  type MyBoxItem struct {
      Name string
  }
  
  type MyBox struct {
      Items []MyBoxItem
  }
  
  func (box *MyBox) AddItem(item MyBoxItem) []MyBoxItem {
      box.Items = append(box.Items, item)
      return box.Items
  }
  
  func PrintCustomArray(list interface{}) interface{}  {
      //items := reflect.ValueOf(list)
      for _, v := range list {
          fmt.Println(v.Key,v.Value)
      }
      return 0
  }
  func main() {
  
      items := []MyBoxItem{}
      item := MyBoxItem{Name: "Test Item 1"}
      box := MyBox{items}
      box.AddItem(item)
      fmt.Println((box.Items))
      PrintCustomArray(box.Items)
  }
  </code></pre>
  
  <p><a href="https://play.golang.org/p/ZcIBLMliq3" rel="nofollow noreferrer">https://play.golang.org/p/ZcIBLMliq3</a></p>
  
  <p>Error : <code>cannot range over list (type interface {})</code></p>
  
  <p>How can fix?</p>