Skip to content

Commit

Permalink
docs(storage): add comment in doc on how to use STORAGE_EMULATOR_HOST (
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennaEpp committed Aug 27, 2021
1 parent 8467899 commit 3c2bf7b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions storage/doc.go
Expand Up @@ -48,6 +48,31 @@ an unauthenticated client with
client, err := storage.NewClient(ctx, option.WithoutAuthentication())
To use an emulator with this library, you can set the STORAGE_EMULATOR_HOST
environment variable to the address at which your emulator is running. This will
send requests to that address instead of to Cloud Storage. You can then create
and use a client as usual:
// Set STORAGE_EMULATOR_HOST environment variable.
err := os.Setenv("STORAGE_EMULATOR_HOST", "localhost:9000")
if err != nil {
// TODO: Handle error.
}
// Create client as usual.
client, err := storage.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
// This request is now directed to http://localhost:9000/storage/v1/b
// instead of https://storage.googleapis.com/storage/v1/b
if err := client.Bucket("my-bucket").Create(ctx, projectID, nil); err != nil {
// TODO: Handle error.
}
Please note that there is no official emulator for Cloud Storage.
Buckets
A Google Cloud Storage bucket is a collection of objects. To work with a
Expand Down

0 comments on commit 3c2bf7b

Please sign in to comment.