title: Reflect on struct passed into interface{} function parameter
body: <p>I pass struct into a function as <code>interface{}</code>. Then inside I work with it using <code>reflect</code> to get the struct attributes. Here's the code:</p>
  <pre><code>func (db *DB) Migrate(domain ...interface{}) {
      // statement := &quot;CREATE TABLE IF NOT EXISTS %s (%s, %s, %s, %s, %s)&quot;
      for _,i := range domain {
          params := BindStruct(&amp;i)
          statement := CreateStatement(&quot;create&quot;, len(params))
          _,err := db.Exec(fmt.Sprintf(statement, params...))
          if err != nil {
              log.Fatal(&quot;Error migrating database schema - &quot;, err)
              break
          }
      }
  } 
  
  func BindStruct(domain interface{}) (params []interface{}) {
      tableName := reflect.TypeOf(domain).Elem().Name()
      params = append(params, tableName)
  
      val := reflect.ValueOf(domain).Elem()
      for i:=0; i &lt; val.NumField(); i++ {
          field := val.Type().Field(i)
          tag := field.Tag
  
          fieldName := field.Name
          fieldType := tag.Get(&quot;sql_type&quot;)
          fieldTags := tag.Get(&quot;sql_tag&quot;)
          
          paramstring := fieldName + &quot; &quot; + fieldType + &quot; &quot; + fieldTags
          params = append(params, paramstring)
      }
      return params
  }
  </code></pre>
  <p>I got an error on the line <code>for i:=0; i &lt; val.NumField(); i++ {</code> in <code>BindStruct</code> function. The error message is:</p>
  <blockquote>
  <p>panic: reflect: call of reflect.Value.NumField on interface Value</p>
  </blockquote>
  <p>If I remove <code>&amp;</code> from <code>params := BindStruct(&amp;i)</code> becoming <code>params := BindStruct(i)</code> in Migrate function, I get this error:</p>
  <blockquote>
  <p>panic: runtime error: invalid memory address or nil pointer</p>
  <p>dereference[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4ff457]</p>
  </blockquote>
  <p>What gives?</p>