| 1 |
## Cloud Storage [](https://pkg.go.dev/cloud.google.com/go/storage) |
| 2 |
|
| 3 |
- [About Cloud Storage](https://cloud.google.com/storage/) |
| 4 |
- [API documentation](https://cloud.google.com/storage/docs) |
| 5 |
- [Go client documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest) |
| 6 |
- [Complete sample programs](https://github.com/GoogleCloudPlatform/golang-samples/tree/main/storage) |
| 7 |
|
| 8 |
### Example Usage |
| 9 |
|
| 10 |
First create a `storage.Client` to use throughout your application: |
| 11 |
|
| 12 |
[snip]:# (storage-1) |
| 13 |
```go |
| 14 |
client, err := storage.NewClient(ctx) |
| 15 |
if err != nil { |
| 16 |
log.Fatal(err) |
| 17 |
} |
| 18 |
``` |
| 19 |
|
| 20 |
[snip]:# (storage-2) |
| 21 |
```go |
| 22 |
// Read the object1 from bucket. |
| 23 |
rc, err := client.Bucket("bucket").Object("object1").NewReader(ctx) |
| 24 |
if err != nil { |
| 25 |
log.Fatal(err) |
| 26 |
} |
| 27 |
defer rc.Close() |
| 28 |
body, err := io.ReadAll(rc) |
| 29 |
if err != nil { |
| 30 |
log.Fatal(err) |
| 31 |
} |
| 32 |
``` |