2021-02-09 00:12:07 +01:00
|
|
|
## Cloud Storage [![Go Reference](https://pkg.go.dev/badge/cloud.google.com/go/storage.svg)](https://pkg.go.dev/cloud.google.com/go/storage)
|
2019-11-07 20:05:39 +01:00
|
|
|
|
|
|
|
- [About Cloud Storage](https://cloud.google.com/storage/)
|
|
|
|
- [API documentation](https://cloud.google.com/storage/docs)
|
2022-09-26 14:44:55 +02:00
|
|
|
- [Go client documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest)
|
2022-01-27 12:16:16 +01:00
|
|
|
- [Complete sample programs](https://github.com/GoogleCloudPlatform/golang-samples/tree/main/storage)
|
2019-11-07 20:05:39 +01:00
|
|
|
|
|
|
|
### Example Usage
|
|
|
|
|
|
|
|
First create a `storage.Client` to use throughout your application:
|
|
|
|
|
|
|
|
[snip]:# (storage-1)
|
|
|
|
```go
|
|
|
|
client, err := storage.NewClient(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
[snip]:# (storage-2)
|
|
|
|
```go
|
|
|
|
// Read the object1 from bucket.
|
|
|
|
rc, err := client.Bucket("bucket").Object("object1").NewReader(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer rc.Close()
|
2022-11-10 12:46:33 +01:00
|
|
|
body, err := io.ReadAll(rc)
|
2019-11-07 20:05:39 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-02-09 00:12:07 +01:00
|
|
|
```
|