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

Function ExampleCollection_As

docstore/example_test.go:115–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115func ExampleCollection_As() {
116 // This example is specific to the gcpfirestore implementation; it demonstrates
117 // access to the underlying *cloud.google.com/go/firestore/apiv1.Client.
118
119 // You will need to blank-import the package for this to work:
120 // import _ "gocloud.dev/docstore/gcpfirestore"
121
122 // The types exposed for As by gcpfirestore are documented in
123 // https://godoc.org/gocloud.dev/docstore/gcpfirestore#hdr-As
124
125 // This URL will open the collection using default credentials.
126 ctx := context.Background()
127 coll, err := docstore.OpenCollection(ctx,
128 "firestore://projects/myproject/databases/(default)/documents/mycollection?name_field=myID")
129 if err != nil {
130 log.Fatal(err)
131 }
132 defer coll.Close()
133
134 // Try to access and use the underlying mongo.Collection.
135 var fsClient *firestore.Client
136 if coll.As(&fsClient) {
137 _ = fsClient // TODO: Use the client.
138 } else {
139 log.Println("Unable to access firestore.Client through Collection.As")
140 }
141}
142
143func ExampleCollection_ErrorAs() {
144 // This example is specific to the awsdynamodb implementation.

Callers

nothing calls this directly

Calls 3

OpenCollectionFunction · 0.92
CloseMethod · 0.65
AsMethod · 0.65

Tested by

no test coverage detected