From 3c2bf7b15ccb96b5e91a432fc052836f68935d29 Mon Sep 17 00:00:00 2001 From: Brenna N Epp Date: Fri, 27 Aug 2021 13:23:32 -0500 Subject: [PATCH] docs(storage): add comment in doc on how to use STORAGE_EMULATOR_HOST (#4656) --- storage/doc.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/storage/doc.go b/storage/doc.go index 750e183496a..418e16068a9 100644 --- a/storage/doc.go +++ b/storage/doc.go @@ -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