Skip to content

Commit

Permalink
Revert "Draft: Add Err() function to Response for detailed errors (op…
Browse files Browse the repository at this point in the history
…ensearch-project#246)"

This reverts commit 8d3cf4d.

Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed May 18, 2023
1 parent 1802363 commit ffed0df
Show file tree
Hide file tree
Showing 157 changed files with 221 additions and 454 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds Github workflow for changelog verification ([#172](https://github.com/opensearch-project/opensearch-go/pull/172))
- Adds Go Documentation link for the client ([#182](https://github.com/opensearch-project/opensearch-go/pull/182))
- Adds implementation of Data Streams API ([#257](https://github.com/opensearch-project/opensearch-go/pull/257)
- Adds `Err()` function to Response for detailed errors ([#246](https://github.com/opensearch-project/opensearch-go/pull/246))
- Adds Point In Time API ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))
- Adds InfoResp type ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))
- Adds markdown linter ([#261](https://github.com/opensearch-project/opensearch-go/pull/261))
Expand Down
95 changes: 0 additions & 95 deletions UPGRADING.md

This file was deleted.

84 changes: 35 additions & 49 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,19 @@ In the example below, we create a client, an index with non-default settings, in
package main

import (
"os"
"context"
"crypto/tls"
"errors"
"fmt"
"net/http"
"os"
"strings"

opensearch "github.com/opensearch-project/opensearch-go/v2"
opensearchapi "github.com/opensearch-project/opensearch-go/v2/opensearchapi"
"net/http"
"strings"
)

const IndexName = "go-test-index1"

func main() {
if err := example(); err != nil {
fmt.Println(fmt.Sprintf("Error: %s", err))
os.Exit(1)
}
}

func example() error {

// Initialize the client with SSL/TLS enabled.
client, err := opensearch.NewClient(opensearch.Config{
Expand All @@ -48,7 +39,8 @@ func example() error {
Password: "admin",
})
if err != nil {
return err
fmt.Println("cannot initialize", err)
os.Exit(1)
}

// Print OpenSearch version information on console.
Expand All @@ -68,18 +60,10 @@ func example() error {
Index: IndexName,
Body: mapping,
}
ctx := context.Background()
var opensearchError *opensearchapi.Error
createIndexResponse, err := createIndex.Do(ctx, client)
// Load err into opensearchapi.Error to access the fields and tolerate if the index already exists
createIndexResponse, err := createIndex.Do(context.Background(), client)
if err != nil {
if errors.As(err, &opensearchError) {
if opensearchError.Err.Type != "resource_already_exists_exception" {
return err
}
} else {
return err
}
fmt.Println("failed to create index ", err)
os.Exit(1)
}
fmt.Println(createIndexResponse)

Expand All @@ -96,9 +80,10 @@ func example() error {
DocumentID: docId,
Body: document,
}
insertResponse, err := req.Do(ctx, client)
insertResponse, err := req.Do(context.Background(), client)
if err != nil {
return err
fmt.Println("failed to insert document ", err)
os.Exit(1)
}
fmt.Println(insertResponse)

Expand All @@ -117,21 +102,23 @@ func example() error {
Body: content,
}

searchResponse, err := search.Do(ctx, client)
searchResponse, err := search.Do(context.Background(), client)
if err != nil {
return err
fmt.Println("failed to search document ", err)
os.Exit(1)
}
fmt.Println(searchResponse)

// Delete the document.
deleteReq := opensearchapi.DeleteRequest{
delete := opensearchapi.DeleteRequest{
Index: IndexName,
DocumentID: docId,
}

deleteResponse, err := deleteReq.Do(ctx, client)
deleteResponse, err := delete.Do(context.Background(), client)
if err != nil {
return err
fmt.Println("failed to delete document ", err)
os.Exit(1)
}
fmt.Println("deleting document")
fmt.Println(deleteResponse)
Expand All @@ -141,26 +128,14 @@ func example() error {
Index: []string{IndexName},
}

deleteIndexResponse, err := deleteIndex.Do(ctx, client)
deleteIndexResponse, err := deleteIndex.Do(context.Background(), client)
if err != nil {
return err
fmt.Println("failed to delete index ", err)
os.Exit(1)
}
fmt.Println("deleting index", deleteIndexResponse)

// Try to delete the index again which failes as it does not exist
// Load err into opensearchapi.Error to access the fields and tolerate if the index is missing
_, err = deleteIndex.Do(ctx, client)
if err != nil {
if errors.As(err, &opensearchError) {
if opensearchError.Err.Type != "index_not_found_exception" {
return err
}
} else {
return err
}
}
return nil
}

```

## Amazon OpenSearch Service
Expand Down Expand Up @@ -225,6 +200,17 @@ func main() {
}
defer resp.Body.Close()

if resp.IsError() {
log.Printf("ping response status: %q", resp.Status())

respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("failed to read response body body: %v", err)
}

log.Fatalf("ping resp body: %s", respBody)
}

log.Println("PING OK")
}
```
Expand Down Expand Up @@ -294,7 +280,7 @@ func main() {
Index: indexName,
Body: mapping,
}
createIndexResponse, err := createIndex.Do(ctx, client)
createIndexResponse, err := createIndex.Do(context.Background(), client)
if err != nil {
log.Fatalf("failed to create index: %v", err)
}
Expand All @@ -305,7 +291,7 @@ func main() {
Index: []string{indexName},
}

deleteIndexResponse, err := deleteIndex.Do(ctx, client)
deleteIndexResponse, err := deleteIndex.Do(context.Background(), client)
if err != nil {
log.Fatalf("failed to delete index: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (r BulkRequest) Do(ctx context.Context, transport Transport) (*Response, er
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r CatAliasesRequest) Do(ctx context.Context, transport Transport) (*Respon
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (r CatAllocationRequest) Do(ctx context.Context, transport Transport) (*Res
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (r CatClusterManagerRequest) Do(ctx context.Context, transport Transport) (
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.count.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r CatCountRequest) Do(ctx context.Context, transport Transport) (*Response
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.fielddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r CatFielddataRequest) Do(ctx context.Context, transport Transport) (*Resp
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.health.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (r CatHealthRequest) Do(ctx context.Context, transport Transport) (*Respons
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.help.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r CatHelpRequest) Do(ctx context.Context, transport Transport) (*Response,
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (r CatIndicesRequest) Do(ctx context.Context, transport Transport) (*Respon
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.master.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (r CatMasterRequest) Do(ctx context.Context, transport Transport) (*Respons
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.nodeattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r CatNodeattrsRequest) Do(ctx context.Context, transport Transport) (*Resp
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (r CatNodesRequest) Do(ctx context.Context, transport Transport) (*Response
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api.cat.pending_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (r CatPendingTasksRequest) Do(ctx context.Context, transport Transport) (*R
Header: res.Header,
}

return &response, response.Err()
return &response, nil
}

// WithContext sets the request context.
Expand Down
Loading

0 comments on commit ffed0df

Please sign in to comment.