Skip to content

Instantly share code, notes, and snippets.

@darthberen
Created February 8, 2015 19:32
Show Gist options
  • Save darthberen/963313f71b97b029c03f to your computer and use it in GitHub Desktop.
Save darthberen/963313f71b97b029c03f to your computer and use it in GitHub Desktop.
excerpt of decode.go code
// lines 559-583 in decode.go in encoding/json package
var f *field
fields := cachedTypeFields(v.Type())
for i := range fields {
ff := &fields[i]
if bytes.Equal(ff.nameBytes, key) {
f = ff
break
}
if f == nil && ff.equalFold(ff.nameBytes, key) {
f = ff
}
}
if f != nil {
subv = v
destring = f.quoted
for _, i := range f.index {
if subv.Kind() == reflect.Ptr {
if subv.IsNil() {
subv.Set(reflect.New(subv.Type().Elem()))
}
subv = subv.Elem()
}
subv = subv.Field(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment