Skip to content

Commit

Permalink
Fixed git issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
serejja committed Mar 24, 2015
1 parent adf6ab9 commit c587c73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
12 changes: 9 additions & 3 deletions datum_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,22 @@ func (this *SpecificDatumWriter) writeRecord(v reflect.Value, enc Encoder, s Sch
}

func (this *SpecificDatumWriter) findField(where reflect.Value, name string) (reflect.Value, error) {
elem := where.Elem() //TODO maybe check first?
field := elem.FieldByName(strings.ToUpper(name[0:1]) + name[1:])
if where.Kind() == reflect.Ptr {
where = where.Elem()
}
field := where.FieldByName(strings.ToUpper(name[0:1]) + name[1:])
if !field.IsValid() {
field = elem.FieldByName(name)
field = where.FieldByName(name)
}

if !field.IsValid() {
return reflect.Zero(nil), fmt.Errorf("Field %s does not exist", name)
}

if field.Kind() == reflect.Interface {
return field.Elem(), nil
}

return field, nil
}

Expand Down
22 changes: 0 additions & 22 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"reflect"
"strings"
)

const (
Expand Down Expand Up @@ -899,24 +898,3 @@ func dereference(v reflect.Value) reflect.Value {

return v
}

func findField(where reflect.Value, name string) (reflect.Value, bool) {
if where.Kind() != reflect.Struct {
return reflect.ValueOf(nil), false
}

field := where.FieldByName(strings.ToUpper(name[0:1]) + name[1:])
if !field.IsValid() {
field = where.FieldByName(name)
}

if !field.IsValid() {
return reflect.ValueOf(nil), false
}

if field.Kind() == reflect.Interface {
field = field.Elem()
}

return field, true
}

0 comments on commit c587c73

Please sign in to comment.