Skip to content

Commit

Permalink
[Cosmos] Add preferred regions to CosmosClientOptions (#22206)
Browse files Browse the repository at this point in the history
* added to client options, added sample

* pointers lol

* Update example_test.go
  • Loading branch information
simorenoh authored Jan 12, 2024
1 parent 0677fb4 commit 58fcfdd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/data/azcosmos/cosmos_client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ type ClientOptions struct {
// When EnableContentResponseOnWrite is false will cause the response to have a null resource. This reduces networking and CPU load by not sending the resource back over the network and serializing it on the client.
// The default is false.
EnableContentResponseOnWrite bool
// PreferredRegions is a list of regions to be used when initializing the client in case the default region fails.
PreferredRegions []string
}
27 changes: 27 additions & 0 deletions sdk/data/azcosmos/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@ func ExampleNewClientFromConnectionString() {
fmt.Println(client)
}

func ExampleClientOptions_PreferredRegions() {
clientOptions := azcosmos.ClientOptions{PreferredRegions: []string{"West US", "Central US"}}

endpoint, ok := os.LookupEnv("AZURE_COSMOS_ENDPOINT")
if !ok {
panic("AZURE_COSMOS_ENDPOINT could not be found")
}

key, ok := os.LookupEnv("AZURE_COSMOS_KEY")
if !ok {
panic("AZURE_COSMOS_KEY could not be found")
}

// Create new Cosmos DB client.
cred, err := azcosmos.NewKeyCredential(key)
if err != nil {
panic(err)
}

client, err := azcosmos.NewClientWithKey(endpoint, cred, &clientOptions)
if err != nil {
panic(err)
}

fmt.Println(client)
}

func ExampleClient_CreateDatabase() {
endpoint, ok := os.LookupEnv("AZURE_COSMOS_ENDPOINT")
if !ok {
Expand Down

0 comments on commit 58fcfdd

Please sign in to comment.