From 9c4b46c5bfc7687cd6f629bbf2b8c5432f1b11b3 Mon Sep 17 00:00:00 2001 From: rahul2393 Date: Sat, 4 Sep 2021 11:55:01 +0530 Subject: [PATCH] docs(spanner): add example for using SPANNER_EMULATOR_HOST (#4723) Co-authored-by: Hengfeng Li --- spanner/doc.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spanner/doc.go b/spanner/doc.go index 66cb015e8d6a..5471ef290577 100644 --- a/spanner/doc.go +++ b/spanner/doc.go @@ -41,6 +41,22 @@ of interest: Remember to close the client after use to free up the sessions in the session pool. +To use an emulator with this library, you can set the SPANNER_EMULATOR_HOST +environment variable to the address at which your emulator is running. This will +send requests to that address instead of to Cloud Spanner. You can then create +and use a client as usual: + + // Set SPANNER_EMULATOR_HOST environment variable. + err := os.Setenv("SPANNER_EMULATOR_HOST", "localhost:9010") + if err != nil { + // TODO: Handle error. + } + // Create client as usual. + client, err := spanner.NewClient(ctx, "projects/P/instances/I/databases/D") + if err != nil { + // TODO: Handle error. + } + Simple Reads and Writes