Skip to content

Commit

Permalink
docs(spanner): add example for using SPANNER_EMULATOR_HOST (#4723)
Browse files Browse the repository at this point in the history
Co-authored-by: Hengfeng Li <hengfeng@google.com>
  • Loading branch information
rahul2393 and hengfengli authored Sep 4, 2021
1 parent 33e4d89 commit 9c4b46c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spanner/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c4b46c

Please sign in to comment.