MCPcopy Create free account
hub / github.com/google/go-cloud / getDocument

Method getDocument

docstore/driver/document.go:80–101  ·  view source on GitHub ↗

getDocument gets the value of the given field path, which must be a document. If create is true, it creates intermediate documents as needed.

(fp []string, create bool)

Source from the content-addressed store, hash-verified

78// getDocument gets the value of the given field path, which must be a document.
79// If create is true, it creates intermediate documents as needed.
80func (d Document) getDocument(fp []string, create bool) (Document, error) {
81 if len(fp) == 0 {
82 return d, nil
83 }
84 x, err := d.GetField(fp[0])
85 if err != nil {
86 if create && gcerrors.Code(err) == gcerrors.NotFound {
87 // TODO(jba): create the right type for the struct field.
88 x = map[string]any{}
89 if err := d.SetField(fp[0], x); err != nil {
90 return Document{}, err
91 }
92 } else {
93 return Document{}, err
94 }
95 }
96 d2, err := NewDocument(x)
97 if err != nil {
98 return Document{}, err
99 }
100 return d2.getDocument(fp[1:], create)
101}
102
103// Get returns the value of the given field path in the document.
104func (d Document) Get(fp []string) (any, error) {

Callers 2

GetMethod · 0.95
SetMethod · 0.95

Calls 4

GetFieldMethod · 0.95
SetFieldMethod · 0.95
CodeFunction · 0.92
NewDocumentFunction · 0.85

Tested by

no test coverage detected