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

Function ExampleBucket_ErrorAs

blob/example_test.go:165–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163}
164
165func ExampleBucket_ErrorAs() {
166 // This example is specific to the s3blob implementation; it demonstrates
167 // access to the underlying smithy.APIError type.
168 // The types exposed for ErrorAs by s3blob are documented in
169 // https://godoc.org/gocloud.dev/blob/s3blob#hdr-As
170
171 ctx := context.Background()
172
173 b, err := blob.OpenBucket(ctx, "s3://my-bucket")
174 if err != nil {
175 log.Fatal(err)
176 }
177 defer b.Close()
178
179 _, err = b.ReadAll(ctx, "nosuchfile")
180 if err != nil {
181 var awsErr smithy.APIError
182 if b.ErrorAs(err, &awsErr) {
183 fmt.Println(awsErr.ErrorCode())
184 }
185 // Alternatively, using the Go built-in errors package:
186 if errors.As(err, &awsErr) {
187 fmt.Println(awsErr.ErrorCode())
188 }
189 }
190}
191
192func ExampleBucket_List() {
193 // Connect to a bucket when your program starts up.

Callers

nothing calls this directly

Calls 6

OpenBucketFunction · 0.92
ReadAllMethod · 0.80
CloseMethod · 0.65
ErrorAsMethod · 0.65
ErrorCodeMethod · 0.65
AsMethod · 0.65

Tested by

no test coverage detected