()
| 141 | } |
| 142 | |
| 143 | func ExampleCollection_ErrorAs() { |
| 144 | // This example is specific to the awsdynamodb implementation. |
| 145 | // You will need to blank-import the package for this to work: |
| 146 | // import _ "gocloud.dev/docstore/awsdynamodb/v2" |
| 147 | |
| 148 | // The types exposed for As by mongodocstore are documented in |
| 149 | // https://godoc.org/gocloud.dev/docstore/mongodocstore#hdr-As |
| 150 | |
| 151 | // This URL will open the collection using default credentials. |
| 152 | ctx := context.Background() |
| 153 | coll, err := docstore.OpenCollection(ctx, "dynamodb://mytable?partition_key=partkey") |
| 154 | if err != nil { |
| 155 | log.Fatal(err) |
| 156 | } |
| 157 | defer coll.Close() |
| 158 | |
| 159 | doc := map[string]any{"_id": "a"} |
| 160 | if err := coll.Create(ctx, doc); err != nil { |
| 161 | var aerr smithy.APIError |
| 162 | if coll.ErrorAs(err, &aerr) { |
| 163 | fmt.Println("got", aerr) |
| 164 | } else { |
| 165 | fmt.Println("could not convert error") |
| 166 | } |
| 167 | // Alternatively, using errors.As: |
| 168 | _ = errors.As(err, &aerr) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | func ExampleQuery_Get() { |
| 173 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |
nothing calls this directly
no test coverage detected