func getObjectFromDoc(doc *pb.Document) (*pb.Object, error) { root := doc.GetRoot() if root == nil { return nil, fmt.Errorf("document '%s' does not have a root", doc.Name) } obj := root.GetObject() if obj == nil { return nil, fmt.Errorf("root field of document '%s' does not have an object as it's value", doc.Name) } return obj, nil }
// GetFieldFromDocument returns a pointer to field in doc based on the given field path. func GetFieldFromDocument(doc *pb.Document, fieldpath string) (*pb.Field, error) { root := doc.GetRoot() if root == nil { return nil, fmt.Errorf("root for document '%s' was nil", doc.Name) } field, err := ResolveRelativeField(root, fieldpath) if err != nil { return nil, fmt.Errorf("could not resolve '%s': %v", fieldpath, err) } return field, err }