title: golang - how to get element from the interface{} type of slice?
body: <p>I want to write a function that can convert slice([]int, []string, []bool, []int64, []float64) to string.</p>
  
  <pre><code>[]string{a,b,c} -&gt; a,b,c
  []int{1,2,3}    -&gt; 1,2,3
  </code></pre>
  
  <p>There is my <a href="http://play.golang.org/p/QgwFJAsYwg" rel="nofollow">code</a>:</p>
  
  <pre><code>func sliceToString(itr interface{}) string {
      switch itr.(type) {
      case []string:
          return strings.Join(itr.([]string), ",")
      case []int:
          s := []string{}
          for _, v := range itr.([]int) {
              s = append(s, fmt.Sprintf("%v", v))
          }
          return strings.Join(s, ",")
      case []int64:
          s := []string{}
          for _, v := range itr.([]int64) {
              s = append(s, fmt.Sprintf("%v", v))
          }
          return strings.Join(s, ",")
      case []float64:
          s := []string{}
          for _, v := range itr.([]float64) {
              s = append(s, fmt.Sprintf("%v", v))
          }
          return strings.Join(s, ",")
      case []bool:
          s := []string{}
          for _, v := range itr.([]bool) {
              s = append(s, fmt.Sprintf("%v", v))
          }
          return strings.Join(s, ",")
      }
  
      return ""
  }
  </code></pre>
  
  <p>But it's a little complicated, if i can convert interface{}(type is slice) to []interface{} or get element , it's getting more simple.</p>
  
  <pre><code> func sliceToString(itr interface{}) string {
      s := []string{}
      // convert interface{} to []interface{} or get elements
      // els := ...
      for _,v:= range els{
         s = append(s, fmt.Sprintf("%v", v))
      }
      return s
   }
  </code></pre>