Skip to content

Commit 13189cf

Browse files
committed
chore: replace all ioutil with io references
1 parent a6c39bb commit 13189cf

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"github.com/google/go-querystring/query"
10-
"github.com/google/uuid"
119
"io"
12-
"io/ioutil"
1310
"net/http"
1411
"net/url"
1512
"runtime"
1613
"time"
14+
15+
"github.com/google/go-querystring/query"
16+
"github.com/google/uuid"
1717
)
1818

1919
var apiBaseURL = &url.URL{
@@ -109,9 +109,9 @@ func (c *Client) setParameters(req *http.Request, params interface{}) error {
109109
if err != nil {
110110
return err
111111
}
112-
req.Body = ioutil.NopCloser(bytes.NewReader(buf))
112+
req.Body = io.NopCloser(bytes.NewReader(buf))
113113
req.GetBody = func() (io.ReadCloser, error) {
114-
return ioutil.NopCloser(bytes.NewReader(buf)), nil
114+
return io.NopCloser(bytes.NewReader(buf)), nil
115115
}
116116
req.Header.Set("Content-Type", "application/json")
117117
// Setting Content-Length avoids chunked encoding, which the API

mocking.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package easypost
22

33
import (
44
"io"
5-
"io/ioutil"
65
"net/http"
76
"regexp"
87
"strings"
@@ -19,7 +18,7 @@ type MockRequestResponseInfo struct {
1918
}
2019

2120
func (r *MockRequestResponseInfo) MockBody() io.ReadCloser {
22-
return ioutil.NopCloser(strings.NewReader(r.Body))
21+
return io.NopCloser(strings.NewReader(r.Body))
2322
}
2423

2524
type MockRequest struct {

referral_customer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"net/url"
109
"strings"
@@ -185,7 +184,7 @@ func (c *Client) createStripeToken(ctx context.Context, stripeApiKey string, cre
185184
_ = Body.Close()
186185
}(resp.Body)
187186

188-
body, err := ioutil.ReadAll(resp.Body) // deprecated, but we have to keep it for legacy compatibility
187+
body, err := io.ReadAll(resp.Body) // deprecated, but we have to keep it for legacy compatibility
189188
if err != nil {
190189
return nil, err
191190
}

tests/bootstrap_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"os"
1111
"path/filepath"
@@ -183,7 +183,7 @@ func (c *ClientTests) SetupTest() {
183183
if _, err := b.ReadFrom(r.Body); err != nil {
184184
return false
185185
}
186-
r.Body = ioutil.NopCloser(&b)
186+
r.Body = io.NopCloser(&b)
187187
bString := b.String()
188188
if bString == "" && i.Body == "" {
189189
// short circuit and return true if the body is empty as it should be

tests/fixture_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bufio"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"path/filepath"
1010
"time"
@@ -13,25 +13,25 @@ import (
1313
)
1414

1515
type Fixture struct {
16-
Addresses map[string]*easypost.Address `json:"addresses,omitempty" url:"addresses,omitempty"`
17-
CarrierAccounts map[string]*easypost.CarrierAccount `json:"carrier_accounts,omitempty" url:"carrier_accounts,omitempty"`
18-
CarrierStrings map[string]string `json:"carrier_strings,omitempty" url:"carrier_strings,omitempty"`
19-
Claims map[string]*easypost.CreateClaimParameters `json:"claims,omitempty" url:"claims,omitempty"`
20-
CustomsInfos map[string]*easypost.CustomsInfo `json:"customs_infos,omitempty" url:"customs_infos,omitempty"`
21-
CustomsItems map[string]*easypost.CustomsItem `json:"customs_items,omitempty" url:"customs_items,omitempty"`
22-
CreditCards map[string]*easypost.CreditCardOptions `json:"credit_cards,omitempty" url:"credit_cards,omitempty"`
23-
FormOptions map[string]map[string]interface{} `json:"form_options,omitempty" url:"form_options,omitempty"`
24-
Insurances map[string]*easypost.Insurance `json:"insurances,omitempty" url:"insurances,omitempty"`
25-
Orders map[string]*easypost.Order `json:"orders,omitempty" url:"orders,omitempty"`
26-
PageSizes map[string]int `json:"page_sizes,omitempty" url:"page_sizes,omitempty"`
27-
Parcels map[string]*easypost.Parcel `json:"parcels,omitempty" url:"parcels,omitempty"`
28-
Pickups map[string]*easypost.Pickup `json:"pickups,omitempty" url:"pickups,omitempty"`
29-
ReportTypes map[string]string `json:"report_types,omitempty" url:"report_types,omitempty"`
30-
ServiceNames map[string]map[string]string `json:"service_names,omitempty" url:"service_names,omitempty"`
31-
Shipments map[string]*easypost.Shipment `json:"shipments,omitempty" url:"shipments,omitempty"`
32-
TaxIdentifiers map[string]*easypost.TaxIdentifier `json:"tax_identifiers,omitempty" url:"tax_identifiers,omitempty"`
33-
Users map[string]*easypost.UserOptions `json:"users,omitempty" url:"users,omitempty"`
34-
Webhooks map[string]interface{} `json:"webhooks,omitempty" url:"webhooks,omitempty"`
16+
Addresses map[string]*easypost.Address `json:"addresses,omitempty" url:"addresses,omitempty"`
17+
CarrierAccounts map[string]*easypost.CarrierAccount `json:"carrier_accounts,omitempty" url:"carrier_accounts,omitempty"`
18+
CarrierStrings map[string]string `json:"carrier_strings,omitempty" url:"carrier_strings,omitempty"`
19+
Claims map[string]*easypost.CreateClaimParameters `json:"claims,omitempty" url:"claims,omitempty"`
20+
CustomsInfos map[string]*easypost.CustomsInfo `json:"customs_infos,omitempty" url:"customs_infos,omitempty"`
21+
CustomsItems map[string]*easypost.CustomsItem `json:"customs_items,omitempty" url:"customs_items,omitempty"`
22+
CreditCards map[string]*easypost.CreditCardOptions `json:"credit_cards,omitempty" url:"credit_cards,omitempty"`
23+
FormOptions map[string]map[string]interface{} `json:"form_options,omitempty" url:"form_options,omitempty"`
24+
Insurances map[string]*easypost.Insurance `json:"insurances,omitempty" url:"insurances,omitempty"`
25+
Orders map[string]*easypost.Order `json:"orders,omitempty" url:"orders,omitempty"`
26+
PageSizes map[string]int `json:"page_sizes,omitempty" url:"page_sizes,omitempty"`
27+
Parcels map[string]*easypost.Parcel `json:"parcels,omitempty" url:"parcels,omitempty"`
28+
Pickups map[string]*easypost.Pickup `json:"pickups,omitempty" url:"pickups,omitempty"`
29+
ReportTypes map[string]string `json:"report_types,omitempty" url:"report_types,omitempty"`
30+
ServiceNames map[string]map[string]string `json:"service_names,omitempty" url:"service_names,omitempty"`
31+
Shipments map[string]*easypost.Shipment `json:"shipments,omitempty" url:"shipments,omitempty"`
32+
TaxIdentifiers map[string]*easypost.TaxIdentifier `json:"tax_identifiers,omitempty" url:"tax_identifiers,omitempty"`
33+
Users map[string]*easypost.UserOptions `json:"users,omitempty" url:"users,omitempty"`
34+
Webhooks map[string]interface{} `json:"webhooks,omitempty" url:"webhooks,omitempty"`
3535
}
3636

3737
// Reads fixture data from the fixtures JSON file
@@ -49,7 +49,7 @@ func readFixtureData() Fixture {
4949

5050
defer func() { _ = data.Close() }()
5151

52-
byteData, _ := ioutil.ReadAll(data)
52+
byteData, _ := io.ReadAll(data)
5353

5454
var fixtures Fixture
5555
_ = json.Unmarshal([]byte(byteData), &fixtures)

0 commit comments

Comments
 (0)