Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
chore: replace deprecated ioutil pkg (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Xu <[email protected]>
  • Loading branch information
maxsxu authored Mar 20, 2023
1 parent aaa1dc6 commit f1908bf
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
3 changes: 1 addition & 2 deletions pkg/admin/auth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package auth

import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -64,7 +63,7 @@ func mockKeyFile(server string) (string, error) {
if err != nil {
return "", err
}
kf, err := ioutil.TempFile(pwd, "test_oauth2")
kf, err := os.CreateTemp(pwd, "test_oauth2")
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/admin/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package auth
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -51,7 +51,7 @@ func NewAuthenticationToken(token string, transport http.RoundTripper) (*TokenAu

// NewAuthenticationTokenFromFile return a interface of a Provider with a string token file path.
func NewAuthenticationTokenFromFile(tokenFilePath string, transport http.RoundTripper) (*TokenAuthProvider, error) {
data, err := ioutil.ReadFile(tokenFilePath)
data, err := os.ReadFile(tokenFilePath)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/admin/auth/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package auth
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
"os"

"github.com/streamnative/pulsar-admin-go/pkg/admin/config"
)
Expand All @@ -45,7 +45,7 @@ func NewDefaultTransport(config *config.Config) (http.RoundTripper, error) {
InsecureSkipVerify: config.TLSAllowInsecureConnection,
}
if len(config.TLSTrustCertsFilePath) > 0 {
rootCA, err := ioutil.ReadFile(config.TLSTrustCertsFilePath)
rootCA, err := os.ReadFile(config.TLSTrustCertsFilePath)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/admin/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"encoding/binary"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -229,7 +228,7 @@ func handleResp(topic utils.TopicName, resp *http.Response) ([]*utils.Message, e
}

// read data
payload, err := ioutil.ReadAll(resp.Body)
payload, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (c *Client) GetWithOptions(endpoint string, obj interface{}, params map[str
return nil, err
}
} else {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -395,7 +394,7 @@ func responseError(resp *http.Response) error {
Reason: resp.Status,
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
e.Reason = err.Error()
return e
Expand Down
4 changes: 2 additions & 2 deletions pkg/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package rest

import (
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -37,7 +37,7 @@ func TestEncodeJSONBody(t *testing.T) {
r, err := encodeJSONBody(testcase.obj)
require.NoError(t, err)

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)

require.Equal(t, testcase.expected, len(b))
Expand Down

0 comments on commit f1908bf

Please sign in to comment.