| 110 | } |
| 111 | |
| 112 | func (d Document) structField(name string) (reflect.Value, error) { |
| 113 | // We do case-insensitive match here to cover the MongoDB's lowercaseFields |
| 114 | // option. |
| 115 | f := d.fields.MatchFold(name) |
| 116 | if f == nil { |
| 117 | return reflect.Value{}, gcerr.Newf(gcerr.NotFound, nil, "field %q not found in struct type %s", name, d.s.Type()) |
| 118 | } |
| 119 | fv, ok := fieldByIndex(d.s, f.Index) |
| 120 | if !ok { |
| 121 | return reflect.Value{}, gcerr.Newf(gcerr.InvalidArgument, nil, "nil embedded pointer; cannot get field %q from %s", |
| 122 | name, d.s.Type()) |
| 123 | } |
| 124 | return fv, nil |
| 125 | } |
| 126 | |
| 127 | // Set sets the value of the field path in the document. |
| 128 | // This creates sub-maps as necessary, if possible. |