MCPcopy Create free account
hub / github.com/golang/appengine / Load

Method Load

search/struct.go:116–190  ·  view source on GitHub ↗
(fields []Field, meta *DocumentMetadata)

Source from the content-addressed store, hash-verified

114}
115
116func (s structFLS) Load(fields []Field, meta *DocumentMetadata) error {
117 var err error
118 for _, field := range fields {
119 i, ok := s.codec.fieldByName[field.Name]
120 if !ok {
121 // Note the error, but keep going.
122 err = &ErrFieldMismatch{
123 FieldName: field.Name,
124 Reason: "no such struct field",
125 }
126 continue
127
128 }
129 f := s.v.Field(i)
130 if !f.CanSet() {
131 // Note the error, but keep going.
132 err = &ErrFieldMismatch{
133 FieldName: field.Name,
134 Reason: "cannot set struct field",
135 }
136 continue
137 }
138 v := reflect.ValueOf(field.Value)
139 if ft, vt := f.Type(), v.Type(); ft != vt {
140 err = &ErrFieldMismatch{
141 FieldName: field.Name,
142 Reason: fmt.Sprintf("type mismatch: %v for %v data", ft, vt),
143 }
144 continue
145 }
146 f.Set(v)
147 }
148 if meta == nil {
149 return err
150 }
151 for _, facet := range meta.Facets {
152 i, ok := s.codec.facetByName[facet.Name]
153 if !ok {
154 // Note the error, but keep going.
155 if err == nil {
156 err = &ErrFacetMismatch{
157 StructType: s.v.Type(),
158 FacetName: facet.Name,
159 Reason: "no matching field found",
160 }
161 }
162 continue
163 }
164 f := s.v.Field(i)
165 if !f.CanSet() {
166 // Note the error, but keep going.
167 if err == nil {
168 err = &ErrFacetMismatch{
169 StructType: s.v.Type(),
170 FacetName: facet.Name,
171 Reason: "unable to set unexported field of struct",
172 }
173 }

Callers

nothing calls this directly

Calls 2

TypeMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected