Skip to content

Commit e8d4c4a

Browse files
docs(go.md): fix an error in the sample code between aws-sdk-go-v2 and opensearch-go/v4 that caused code to not compile. (#9584) (#9586)
1 parent 4113072 commit e8d4c4a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

_clients/go.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ go get github.com/opensearch-project/opensearch-go
2929

3030
## Connecting to OpenSearch
3131

32-
To connect to the default OpenSearch host, create a client object with the address `https://localhost:9200` if you are using the Security plugin:
32+
To connect to the default OpenSearch host, create a client object with the address `https://localhost:9200` if you are using the Security plugin:
3333

3434
```go
3535
client, err := opensearch.NewClient(opensearch.Config{
@@ -66,11 +66,11 @@ import (
6666
"context"
6767
"log"
6868

69-
"github.com/aws/aws-sdk-go-v4/aws"
70-
"github.com/aws/aws-sdk-go-v4/config"
69+
"github.com/aws/aws-sdk-go-v2/aws"
70+
"github.com/aws/aws-sdk-go-v2/config"
7171
opensearch "github.com/opensearch-project/opensearch-go/v4"
72-
opensearchapi "github.com/opensearch-project/opensearch-go/v4@v4.3.0/opensearchapi"
73-
requestsigner "github.com/opensearch-project/opensearch-go/v4@v4.3.0/signer/awsv2"
72+
opensearchapi "github.com/opensearch-project/opensearch-go/v4/opensearchapi"
73+
requestsigner "github.com/opensearch-project/opensearch-go/v4/signer/awsv2"
7474
)
7575

7676
const endpoint = "" // e.g. https://opensearch-domain.region.com or Amazon OpenSearch Serverless endpoint
@@ -102,6 +102,9 @@ func main() {
102102
if err != nil {
103103
log.Fatal("client creation err", err)
104104
}
105+
106+
_ = client
107+
// your code here
105108
}
106109

107110
func getCredentialProvider(accessKey, secretAccessKey, token string) aws.CredentialsProviderFunc {
@@ -128,11 +131,10 @@ import (
128131
"context"
129132
"log"
130133

131-
"github.com/aws/aws-sdk-go-v4/aws"
132-
"github.com/aws/aws-sdk-go-v4/config"
134+
"github.com/aws/aws-sdk-go-v2/aws"
135+
"github.com/aws/aws-sdk-go-v2/config"
133136
opensearch "github.com/opensearch-project/opensearch-go/v4"
134-
opensearchapi "github.com/opensearch-project/opensearch-go/[email protected]/opensearchapi"
135-
requestsigner "github.com/opensearch-project/opensearch-go/[email protected]/signer/awsv2"
137+
requestsigner "github.com/opensearch-project/opensearch-go/v4/signer/awsv2"
136138
)
137139

138140
const endpoint = "" // e.g. https://opensearch-domain.region.com or Amazon OpenSearch Serverless endpoint
@@ -164,6 +166,9 @@ func main() {
164166
if err != nil {
165167
log.Fatal("client creation err", err)
166168
}
169+
170+
_ = client
171+
// your code here
167172
}
168173

169174
func getCredentialProvider(accessKey, secretAccessKey, token string) aws.CredentialsProviderFunc {
@@ -173,7 +178,6 @@ func getCredentialProvider(accessKey, secretAccessKey, token string) aws.Credent
173178
SecretAccessKey: secretAccessKey,
174179
SessionToken: token,
175180
}
176-
return *c, nil
177181
}
178182
}
179183
```
@@ -197,7 +201,7 @@ client, err := opensearch.NewClient(opensearch.Config{
197201
```
198202
{% include copy.html %}
199203

200-
The Go client retries requests for a maximum of three times by default. To customize the number of retries, set the `MaxRetries` parameter. Additionally, you can change the list of response codes for which a request is retried by setting the `RetryOnStatus` parameter. The following code snippet creates a new Go client with custom `MaxRetries` and `RetryOnStatus` values:
204+
The Go client retries requests for a maximum of three times by default. To customize the number of retries, set the `MaxRetries` parameter. Additionally, you can change the list of response codes for which a request is retried by setting the `RetryOnStatus` parameter. The following code snippet creates a new Go client with custom `MaxRetries` and `RetryOnStatus` values:
201205

202206
```go
203207
client, err := opensearch.NewClient(opensearch.Config{
@@ -226,7 +230,7 @@ settings := strings.NewReader(`{
226230
}`)
227231

228232
res := opensearchapi.IndicesCreateRequest{
229-
Index: "go-test-index1",
233+
Index: "go-test-index1",
230234
Body: settings,
231235
}
232236
```
@@ -369,7 +373,7 @@ func main() {
369373

370374
// Create an index with non-default settings.
371375
res := opensearchapi.IndicesCreateRequest{
372-
Index: IndexName,
376+
Index: IndexName,
373377
Body: settings,
374378
}
375379
fmt.Println("Creating index")
@@ -396,7 +400,7 @@ func main() {
396400
fmt.Println("Inserting a document")
397401
fmt.Println(insertResponse)
398402
defer insertResponse.Body.Close()
399-
403+
400404
// Perform bulk operations.
401405
blk, err := client.Bulk(
402406
strings.NewReader(`

0 commit comments

Comments
 (0)