SetField sets the field to value in the document.
(field string, value any)
| 136 | |
| 137 | // SetField sets the field to value in the document. |
| 138 | func (d Document) SetField(field string, value any) error { |
| 139 | if d.m != nil { |
| 140 | d.m[field] = value |
| 141 | return nil |
| 142 | } |
| 143 | v, err := d.structField(field) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | if !v.CanSet() { |
| 148 | return gcerr.Newf(gcerr.InvalidArgument, nil, "cannot set field %s in struct of type %s: not addressable", |
| 149 | field, d.s.Type()) |
| 150 | } |
| 151 | v.Set(reflect.ValueOf(value)) |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | // FieldNames returns names of the top-level fields of d. |
| 156 | func (d Document) FieldNames() []string { |
no test coverage detected