| 163 | } |
| 164 | |
| 165 | func 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 | |
| 192 | func ExampleBucket_List() { |
| 193 | // Connect to a bucket when your program starts up. |