Monday, July 18, 2016

v.IDOrder undefined (type interface {} is interface with no methods)

v.IDOrder undefined (type interface {} is interface with no methods)

  var f = struct {
    IDOrder   int64
    IsClose   bool
    IsConfirm bool
    IDUser    int64
  }{}
  fPtr := util.StructFieldPtrArr(&f)
  outArr := []interface{}{}

  for rs.Next() {
    if err := rs.Scan(fPtr...); err != nil {
      return nil, err
    }

    outArr = append(outArr, f)
  }

  for k, v := range outArr {
    // incorrect
    log.Printf("%v: %v, %v\n", k, v.IDOrder, v.IsConfirm)

    // correct
    log.Printf("%v: %v\n", k, v.(struct {
      IDOrder   int64
      IsClose   bool
      IsConfirm bool
      IDUser    int64
    }).IDOrder)

  }

No comments: