Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Draft: Add Err() function to Response for detailed errors (#2… #383

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added

- 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,29 +15,20 @@ 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"
opensearchutil "github.com/opensearch-project/opensearch-go/v2/opensearchutil"
"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 @@ -49,7 +40,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 @@ -71,18 +63,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 @@ -103,9 +87,10 @@ func example() error {
DocumentID: docId,
Body: opensearchutil.NewJSONReader(&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 @@ -124,21 +109,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 @@ -148,26 +135,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 @@ -232,6 +207,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 @@ -301,7 +287,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 @@ -312,7 +298,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
28 changes: 14 additions & 14 deletions internal/build/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBo
github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/aws/aws-sdk-go v1.44.205/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.17.5/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2/config v1.18.15/go.mod h1:vS0tddZqpE8cD9CyW0/kITHF5Bq2QasW9Y1DFHD//O0=
github.com/aws/aws-sdk-go-v2/credentials v1.13.15/go.mod h1:vRMLMD3/rXU+o6j2MW5YefrGMBmdTvkLLGqFwMLBHQc=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.23/go.mod h1:mOtmAg65GT1HIL/HT/PynwPbS+UG0BgCZ6vhkPqnxWo=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29/go.mod h1:Dip3sIGv485+xerzVv24emnjX5Sg88utCL8fwGmCeWg=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23/go.mod h1:mr6c4cHC+S/MMkrjtSlG4QA36kOznDep+0fga5L/fGQ=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.30/go.mod h1:vsbq62AOBwQ1LJ/GWKFxX8beUEYeRp/Agitrxee2/qM=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.23/go.mod h1:9uPh+Hrz2Vn6oMnQYiUi/zbh3ovbnQk19YKINkQny44=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.4/go.mod h1:jtLIhd+V+lft6ktxpItycqHqiVXrPIRjWIsFIlzMriw=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.4/go.mod h1:zVwRrfdSmbRZWkUkWjOItY7SOalnFnq/Yg2LVPqDjwc=
github.com/aws/aws-sdk-go-v2/service/sts v1.18.5/go.mod h1:1mKZHLLpDMHTNSYPJ7qrcnCQdHCWsNQaT0xRvq2u80s=
github.com/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2/config v1.18.25/go.mod h1:dZnYpD5wTW/dQF0rRNLVypB396zWCcPiBIvdvSWHEg4=
github.com/aws/aws-sdk-go-v2/credentials v1.13.24/go.mod h1:jYPYi99wUOPIFi0rhiOvXeSEReVOzBqFNOX5bXYoG2o=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3/go.mod h1:4Q0UFP0YJf0NrsEuEYHpM9fTSEVnD16Z3uyEF7J9JGM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34/go.mod h1:Etz2dj6UHYuw+Xw830KfzCfWGMzqvUTCjUj5b76GVDc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27/go.mod h1:EOwBD4J4S5qYszS5/3DpkejfuK+Z5/1uzICfPaZLtqw=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10/go.mod h1:AFvkxc8xfBe8XA+5St5XIHHrQQtkxqrRincx4hmMHOk=
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0/go.mod h1:BgQOMsg8av8jset59jelyPW7NoZcZXLVpDsXunGDrk8=
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
Expand Down Expand Up @@ -59,8 +59,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
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
Loading
Loading