From d38bdc15de7a759e3c1c538d173a63eef45a2dd2 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Tue, 26 Mar 2024 14:24:47 +0100 Subject: [PATCH] Replace ioutil with io in examples and integration test (#495) * Replace ioutil with io in examples and integration test - ioutil is deprecated as of Go 1.16. Signed-off-by: Markus Opolka * Update CHANGELOG Signed-off-by: Markus Opolka --------- Signed-off-by: Markus Opolka --- CHANGELOG.md | 1 + _samples/json.go | 10 +++++----- guides/json.md | 10 +++++----- .../opensearchtransport_integration_test.go | 7 +++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ecb2e526..a13d0d0a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Moved functions from opensearch/internal/test to internal/test for more general test uses ([#488](https://github.com/opensearch-project/opensearch-go/pull/488)) - Changed custom_foldername field to pointer as it can be null ([#488](https://github.com/opensearch-project/opensearch-go/pull/488)) - Changed cat indices Primary and Replica field to pointer as it can be null ([#488](https://github.com/opensearch-project/opensearch-go/pull/488)) +- Replace ioutil with io in examples and integration test [#495](https://github.com/opensearch-project/opensearch-go/pull/495) ### Deprecated ### Removed ### Fixed diff --git a/_samples/json.go b/_samples/json.go index 9a7c40f8f..61215c1fa 100644 --- a/_samples/json.go +++ b/_samples/json.go @@ -7,7 +7,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -42,7 +42,7 @@ func example() error { return err } - resBody, err := ioutil.ReadAll(infoResponse.Body) + resBody, err := io.ReadAll(infoResponse.Body) if err != nil { return err } @@ -78,7 +78,7 @@ func example() error { if err != nil { return err } - createIndexRespBody, err := ioutil.ReadAll(createIndexResp.Body) + createIndexRespBody, err := io.ReadAll(createIndexResp.Body) if err != nil { return err } @@ -104,7 +104,7 @@ func example() error { if err != nil { return err } - searchRespBody, err := ioutil.ReadAll(searchResp.Body) + searchRespBody, err := io.ReadAll(searchResp.Body) if err != nil { return err } @@ -120,7 +120,7 @@ func example() error { if err != nil { return err } - deleteIndexRespBody, err := ioutil.ReadAll(deleteIndexResp.Body) + deleteIndexRespBody, err := io.ReadAll(deleteIndexResp.Body) if err != nil { return err } diff --git a/guides/json.md b/guides/json.md index fa6b20213..e65e4337f 100644 --- a/guides/json.md +++ b/guides/json.md @@ -18,7 +18,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -55,7 +55,7 @@ The following example returns the server version information via `GET /`. return err } - resBody, err := ioutil.ReadAll(infoResponse.Body) + resBody, err := io.ReadAll(infoResponse.Body) if err != nil { return err } @@ -95,7 +95,7 @@ The following example creates an index. if err != nil { return err } - createIndexRespBody, err := ioutil.ReadAll(createIndexResp.Body) + createIndexRespBody, err := io.ReadAll(createIndexResp.Body) if err != nil { return err } @@ -127,7 +127,7 @@ The following example searches for a document. if err != nil { return err } - searchRespBody, err := ioutil.ReadAll(searchResp.Body) + searchRespBody, err := io.ReadAll(searchResp.Body) if err != nil { return err } @@ -147,7 +147,7 @@ The following example deletes an index. if err != nil { return err } - deleteIndexRespBody, err := ioutil.ReadAll(deleteIndexResp.Body) + deleteIndexRespBody, err := io.ReadAll(deleteIndexResp.Body) if err != nil { return err } diff --git a/opensearchtransport/opensearchtransport_integration_test.go b/opensearchtransport/opensearchtransport_integration_test.go index 4853841fa..8a7e51419 100644 --- a/opensearchtransport/opensearchtransport_integration_test.go +++ b/opensearchtransport/opensearchtransport_integration_test.go @@ -32,7 +32,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -54,7 +53,7 @@ func TestTransportRetries(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { counter++ - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) fmt.Println("req.Body:", string(body)) http.Error(w, "FAKE 502", http.StatusBadGateway) @@ -82,7 +81,7 @@ func TestTransportRetries(t *testing.T) { t.Fatalf("Unexpected error: %s", err) } - body, _ := ioutil.ReadAll(res.Body) + body, _ := io.ReadAll(res.Body) fmt.Println("> GET", req.URL) fmt.Printf("< %s (tries: %d)\n", bytes.TrimSpace(body), counter) @@ -126,7 +125,7 @@ func TestTransportHeaders(t *testing.T) { } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { t.Fatalf("Unexpected error: %s", err) }