title: dealing with nulls when inserting ints
body: <p>I've written some code that is meant to create inserts from a .csv file.
  Im running into an issue when attempting to insert fields that are NULL values.
  In most cases, the fields within my .csv are ints, but sometimes there need to be NULL in. I know that I cant pass "NULL" as an int, but how can I accommodate for these NULL records when creating my inserts?</p>
  
  <p>In the case of the .csv Im working with, a column: <code>CustomerID</code> which either be an int or it could be a NULL.</p>
  
  <p>Would something like a <code>sql.NullInt64</code> work?</p>
  
  <p>Here's the code I'm working on:</p>
  
  <pre><code>func Unmarshal(reader *csv.Reader, v interface{}) error {
      record, err := reader.Read()
      if err != nil {
          return err
      }
      s := reflect.ValueOf(v).Elem()
      if s.NumField() != len(record) {
          return &amp;FieldMismatch{s.NumField(), len(record)}
      }
      for i := 0; i &lt; s.NumField(); i++ {
          f := s.Field(i)
          switch f.Type().Kind() {
          case reflect.String:
              f.SetString(record[i])
  
          case reflect.Int:
              ival, err := strconv.ParseInt(record[i], 10, f.Type().Bits())
              if err != nil {
                  return err
              }
              f.SetInt(ival)
          case reflect.Float64:
              fval, err := strconv.ParseFloat(record[i], f.Type().Bits())
              if err != nil {
                  return err
              }
              f.SetFloat(fval)
          default:
              return &amp;UnsupportedType{f.Type().String()}
          }
      }
      return nil
  }
  
  type FieldMismatch struct {
      expected, found int
  }
  
  func (e *FieldMismatch) Error() string {
      return "CSV line fields mismatch. Expected " + strconv.Itoa(e.expected) + " found " + strconv.Itoa(e.found)
  }
  
  type UnsupportedType struct {
      Type string
  }
  
  func (e *UnsupportedType) Error() string {
      return "Unsupported type: " + e.Type
  }
  </code></pre>