Skip to content

Commit

Permalink
Replace ioutil with io in examples and integration test (#495)
Browse files Browse the repository at this point in the history
* Replace ioutil with io in examples and integration test

 - ioutil is deprecated as of Go 1.16.

Signed-off-by: Markus Opolka <[email protected]>

* Update CHANGELOG

Signed-off-by: Markus Opolka <[email protected]>

---------

Signed-off-by: Markus Opolka <[email protected]>
  • Loading branch information
martialblog authored Mar 26, 2024
1 parent c72a471 commit d38bdc1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions _samples/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions guides/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions opensearchtransport/opensearchtransport_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d38bdc1

Please sign in to comment.