MCPcopy Index your code
hub / github.com/redspread/spread / getFromMapField

Function getFromMapField

pkg/data/fields.go:114–130  ·  view source on GitHub ↗
(field *pb.Field, key string)

Source from the content-addressed store, hash-verified

112}
113
114func getFromMapField(field *pb.Field, key string) (*pb.Field, error) {
115 fieldMap := field.GetObject()
116 if fieldMap == nil {
117 return nil, fmt.Errorf("field '%s' isn't an object, cannot access %s['%s']", field.Key, field.Key, key)
118 }
119
120 items := fieldMap.GetItems()
121 if items == nil {
122 return nil, fmt.Errorf("the object wrapper struct for the value of field '%s' had nil for items, cannot access %s[%s]", field.Key, field.Key, key)
123 }
124
125 item, ok := items[key]
126 if !ok {
127 return nil, fmt.Errorf("no key '%s' in map for field '%s", key, field.Key)
128 }
129 return item, nil
130}
131
132// nextField returns the first field in a fieldpath and returns the remainder after removing the root element.
133// It will return array as positive number or 0 if refers to array. If there is no next field, an empty string in field will be returned.

Callers 1

ResolveRelativeFieldFunction · 0.85

Calls 2

GetObjectMethod · 0.80
GetItemsMethod · 0.45

Tested by

no test coverage detected