diff --git a/.changelog/1116.txt b/.changelog/1116.txt new file mode 100644 index 00000000000..9e77f423676 --- /dev/null +++ b/.changelog/1116.txt @@ -0,0 +1,3 @@ +```release-note:dependency +deps: `ioutil` package is being deprecated in favor of `io` +``` \ No newline at end of file diff --git a/accounts_test.go b/accounts_test.go index 53455372a4b..bbd0adfb6c1 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -109,7 +109,7 @@ func TestUpdateAccount(t *testing.T) { mux.HandleFunc("/accounts/01a7362d577a6c3019a474fd6f485823", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { diff --git a/cloudflare.go b/cloudflare.go index 9219f723993..952382864b9 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math" "net/http" @@ -57,7 +56,7 @@ type API struct { // newClient provides shared logic for New and NewWithUserServiceKey. func newClient(opts ...Option) (*API, error) { - silentLogger := log.New(ioutil.Discard, "", log.LstdFlags) + silentLogger := log.New(io.Discard, "", log.LstdFlags) api := &API{ BaseURL: fmt.Sprintf("%s://%s%s", defaultScheme, defaultHostname, defaultBasePath), @@ -255,8 +254,8 @@ func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, m if method == http.MethodPost || method == http.MethodPut || method == http.MethodPatch { buf := &bytes.Buffer{} tee := io.TeeReader(reqBody, buf) - debugBody, _ := ioutil.ReadAll(tee) - payloadBody, _ := ioutil.ReadAll(buf) + debugBody, _ := io.ReadAll(tee) + payloadBody, _ := io.ReadAll(buf) fmt.Printf("cloudflare-go [DEBUG] REQUEST Method:%v URI:%s Headers:%#v Body:%v\n", method, api.BaseURL+uri, headers, string(debugBody)) // ensure we recreate the io.Reader for use reqBody = bytes.NewReader(payloadBody) @@ -282,7 +281,7 @@ func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, m // if we got a valid http response, try to read body so we can reuse the connection // see https://golang.org/pkg/net/http/#Client.Do if respErr == nil { - respBody, err = ioutil.ReadAll(resp.Body) + respBody, err = io.ReadAll(resp.Body) resp.Body.Close() respErr = fmt.Errorf("could not read response body: %w", err) @@ -294,7 +293,7 @@ func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, m } continue } else { - respBody, err = ioutil.ReadAll(resp.Body) + respBody, err = io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return nil, fmt.Errorf("could not read response body: %w", err) diff --git a/cloudflare_experimental.go b/cloudflare_experimental.go index 95fdfefc72e..009d3e12493 100644 --- a/cloudflare_experimental.go +++ b/cloudflare_experimental.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -228,8 +227,8 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int if method == http.MethodPost || method == http.MethodPut || method == http.MethodPatch { buf := &bytes.Buffer{} tee := io.TeeReader(reqBody, buf) - debugBody, _ := ioutil.ReadAll(tee) - payloadBody, _ := ioutil.ReadAll(buf) + debugBody, _ := io.ReadAll(tee) + payloadBody, _ := io.ReadAll(buf) c.Logger.Debugf("REQUEST Method:%v URI:%s Headers:%#v Body:%v\n", method, c.BaseURL.String()+uri, headers, string(debugBody)) // ensure we recreate the io.Reader for use reqBody = bytes.NewReader(payloadBody) @@ -244,7 +243,7 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int c.Logger.Debugf("RESPONSE URI:%s StatusCode:%d Body:%#v RayID:%s\n", c.BaseURL.String()+uri, resp.StatusCode, string(respBody), resp.Header.Get("cf-ray")) - respBody, err = ioutil.ReadAll(resp.Body) + respBody, err = io.ReadAll(resp.Body) resp.Body.Close() if err != nil { return nil, fmt.Errorf("could not read response body: %w", err) diff --git a/custom_hostname_test.go b/custom_hostname_test.go index c088a550d80..c38bbbee347 100644 --- a/custom_hostname_test.go +++ b/custom_hostname_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -706,7 +706,7 @@ func TestCustomHostname_UpdateCustomHostname(t *testing.T) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) defer r.Body.Close() - reqBody, err := ioutil.ReadAll(r.Body) + reqBody, err := io.ReadAll(r.Body) assert.NoError(t, err, "Reading request body") assert.JSONEq(t, ` { @@ -786,7 +786,7 @@ func TestCustomHostname_UpdateCustomHostnameWithCustomMetadata(t *testing.T) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) defer r.Body.Close() - reqBody, err := ioutil.ReadAll(r.Body) + reqBody, err := io.ReadAll(r.Body) assert.NoError(t, err, "Reading request body") assert.JSONEq(t, ` { @@ -875,7 +875,7 @@ func TestCustomHostname_UpdateCustomHostnameWithEmptyCustomMetadata(t *testing.T assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) defer r.Body.Close() - reqBody, err := ioutil.ReadAll(r.Body) + reqBody, err := io.ReadAll(r.Body) assert.NoError(t, err, "Reading request body") assert.JSONEq(t, ` { diff --git a/images_test.go b/images_test.go index f2e23bfc284..25ad505d97e 100644 --- a/images_test.go +++ b/images_test.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -363,7 +363,7 @@ func parseImageMultipartUpload(r *http.Request) (imageMultipartUpload, error) { } defer f.Close() - u.File, err = ioutil.ReadAll(f) + u.File, err = io.ReadAll(f) if err != nil { return u, err } @@ -388,7 +388,7 @@ func getImageFormValue(r *http.Request, key string) ([]byte, error) { if err != nil { return nil, err } - return ioutil.ReadAll(file) + return io.ReadAll(file) } return nil, fmt.Errorf("no value found for key %v", key) diff --git a/ips.go b/ips.go index f6e4add3da5..85d1c5bbd0b 100644 --- a/ips.go +++ b/ips.go @@ -3,7 +3,7 @@ package cloudflare import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" ) @@ -41,7 +41,7 @@ func IPs() (IPRanges, error) { return IPRanges{}, fmt.Errorf("HTTP request failed: %w", err) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return IPRanges{}, fmt.Errorf("Response body could not be read: %w", err) } diff --git a/load_balancing_test.go b/load_balancing_test.go index 9413c6517d0..cef7d1b5db5 100644 --- a/load_balancing_test.go +++ b/load_balancing_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -18,7 +18,7 @@ func TestCreateLoadBalancerPool(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ @@ -397,7 +397,7 @@ func TestUpdateLoadBalancerPool(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ @@ -539,7 +539,7 @@ func TestCreateLoadBalancerMonitor(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ @@ -862,7 +862,7 @@ func TestUpdateLoadBalancerMonitor(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ @@ -988,7 +988,7 @@ func TestCreateLoadBalancer(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ @@ -1712,7 +1712,7 @@ func TestUpdateLoadBalancer(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{ diff --git a/logpush_test.go b/logpush_test.go index 7f1f297a6b1..dea1e82deb3 100644 --- a/logpush_test.go +++ b/logpush_test.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "strconv" @@ -246,7 +246,7 @@ func TestCreateLogpushJob(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { diff --git a/origin_ca.go b/origin_ca.go index 7e83a3e6a1e..22c62d975f5 100644 --- a/origin_ca.go +++ b/origin_ca.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -226,7 +226,7 @@ func OriginCARootCertificate(algorithm string) ([]byte, error) { return nil, errors.New(errRequestNotSuccessful) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("Response body could not be read: %w", err) } diff --git a/railgun_test.go b/railgun_test.go index b5589003251..e80c146c853 100644 --- a/railgun_test.go +++ b/railgun_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -18,7 +18,7 @@ func TestCreateRailgun(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) w.Header().Set("content-type", "application/json") - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"name":"My Railgun"}`, string(b)) @@ -254,7 +254,7 @@ func TestEnableRailgun(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"enabled":true}`, string(b)) @@ -315,7 +315,7 @@ func TestDisableRailgun(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"enabled":false}`, string(b)) @@ -543,7 +543,7 @@ func TestConnectRailgun(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"connected":true}`, string(b)) @@ -585,7 +585,7 @@ func TestDisconnectRailgun(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"connected":false}`, string(b)) diff --git a/ssl_test.go b/ssl_test.go index fe1c628e160..78dd51022fc 100644 --- a/ssl_test.go +++ b/ssl_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -17,7 +17,7 @@ func TestCreateSSL(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { @@ -220,7 +220,7 @@ func TestUpdateSSL(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"certificate":"-----BEGIN CERTIFICATE----- MIIDtTCCAp2gAwIBAgIJAM15n7fdxhRtMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV BAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX aWRnaXRzIFB0eSBMdGQwHhcNMTQwMzExMTkyMTU5WhcNMTQwNDEwMTkyMTU5WjBF MQswCQYDVQQGEwJVUzETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50 ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB CgKCAQEAvq3sKsHpeduJHimOK+fvQdKsI8z8A05MZyyLp2/R/GE8FjNv+hkVY1WQ LIyTNNQH7CJecE1nbTfo8Y56S7x/rhxC6/DJ8MIulapFPnorq46KU6yRxiM0MQ3N nTJHlHA2ozZta6YBBfVfhHWl1F0IfNbXCLKvGwWWMbCx43OfW6KTkbRnE6gFWKuO fSO5h2u5TaWVuSIzBvYs7Vza6m+gtYAvKAJV2nSZ+eSEFPDo29corOy8+huEOUL8 5FAw4BFPsr1TlrlGPFitduQUHGrSL7skk1ESGza0to3bOtrodKei2s9bk5MXm7lZ qI+WZJX4Zu9+mzZhc9pCVi8r/qlXuQIDAQABo4GnMIGkMB0GA1UdDgQWBBRvavf+ sWM4IwKiH9X9w1vl6nUVRDB1BgNVHSMEbjBsgBRvavf+sWM4IwKiH9X9w1vl6nUV RKFJpEcwRTELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAM15n7fdxhRtMAwGA1UdEwQF MAMBAf8wDQYJKoZIhvcNAQEFBQADggEBABY2ZzBaW0dMsAAT7tPJzrVWVzQx6KU4 UEBLudIlWPlkAwTnINCWR/8eNjCCmGA4heUdHmazdpPa8RzwOmc0NT1NQqzSyktt vTqb4iHD7+8f9MqJ9/FssCfTtqr/Qst/hGH4Wmdf1EJ/6FqYAAb5iRlPgshFZxU8 uXtA8hWn6fK6eISD9HBdcAFToUvKNZ1BIDPvh9f95Ine8ar6yGd56TUNrHR8eHBs ESxz5ddVR/oWRysNJ+aGAyYqHS8S/ttmC7r4XCAHqXptkHPCGRqkAhsterYhd4I8 /cBzejUobNCjjHFbtkAL/SjxZOLW+pNkZwfeYdM8iPkD54Uua1v2tdw= -----END CERTIFICATE-----","geo_restrictions":{"label":"us"},"private_key":"-----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEAl 1cSc0vfcJLI4ZdWjiZZqy86Eof4czCwilyjXdvHqbdgDjz9H6K/0FX78EzVdfyExESptPCDl5YYjvcZyAWlgNfYEpFpGeoh/pTFW3hlyKImh4EgBXbDrR251J Ew2Nf56X3duibI6X20gKZA6cvdmWeKh MOOXuh1bSPU3dkb4YOF/fng5iGrx0q3txdMQXTPMZ1uXHFcBH7idgViYesXUBhdll3GP1N Y8laq0yrqh 8HMsZK m27MebqonbNmjOqE218lVEvjCdRO6xvNXrO6vNJBoGn2eGwZ8BVd0mTA3Tj43/2cmxQFY9FLq56cCXqYI1fbRRib ZLrjSNkwIDAQABAoIBABfAjjsjjxc0NxcYvKOMUb9Rpj8Sx6U/o/tDC5u XmsGX37aaJmC5yw9BQiAxgvXtQryEl5uoNoqOdsxzKV6yM0vPcwKEJVBd4G6yx6AjVJZnc2qf72erR7BbA2CQh scMDRBKE041HhgTBRNP6roim0SOgYP5JZIrGAQXNIkyE0fZc5gZNUt388ne/mjWM6Xi08BDGurLC68nsdt7Nd UYqeBVxo2EqChp5vKYZYEcG8h9XBj4u4NIwg1Mty2JqX30uBjoHvF5w/pMs8lG uvj6JR9I 19wtCuccbAJl 4cUq03UQoIDmwejea oC8A8WJr3vVpODDWrvAsjllGPBECgYEAyQRa6edYO6bsSvgbM13qXW9OQTn9YmgzfN24Ux1D66TQU6sBSLdfSHshDhTCi Ax 698aJNRWujAakA2DDgspSx98aRnHbF zvY7i7iWGesN6uN0zL 6/MK5uWoieGZRjgk230fLk00l4/FK1mJIp0apr0Lis9xmDjP5AaUPTUUCgYEAwXuhTHZWPT6v8YwOksjbuK UDkIIvyMux53kb73vrkgMboS4DB1zMLNyG 9EghS414CFROUwGl4ZUKboH1Jo5G34y8VgDuHjirTqL2H6 zNpML iMrWCXjpFKkxwPbeQnEAZ 5Rud4d PTyXAt71blZHE9tZ4KHy8cU1iKc9APcCgYAIqKZd4vg7AZK2G//X85iv06aUSrIudfyZyVcyRVVyphPPNtOEVVnGXn9rAtvqeIrOo52BR68 cj4vlXp hkDuEH QVBuY/NdQhOzFtPrKPQTJdGjIlQ2x65Vidj7r3sRukNkLPyV2v D885zcpTkp83JFuWTYiIrg275DIuAI3QKBgAglM0IrzS g3vlVQxvM1ussgRgkkYeybHq82 wUW 3DXLqeXb0s1DedplUkuoabZriz0Wh4GZFSmtA5ZpZC uV697lkYsndmp2xRhaekllW7bu pY5q88URwO2p8CO5AZ6CWFWuBwSDML5VOapGRqDRgwaD oGpb7fb7IgHOls7AoGBAJnL6Q8t35uYJ8J8hY7wso88IE04z6VaT8WganxcndesWER9eFQDHDDy//ZYeyt6M41uIY CL Vkm9Kwl/bHLJKdnOE1a9NdE6mtfah0Bk2u/YOuzyu5mmcgZiX X/OZuEbGmmbZOR1FCuIyrNYfwYohhcZP7/r0Ia/1GpkHc3Bi-----END RSA PRIVATE KEY-----","bundle_method":"ubiquitous"}`, string(b)) @@ -294,7 +294,7 @@ func TestReprioritizeSSL(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"certificates":[{"ID":"5a7805061c76ada191ed06f989cc3dac","priority":2},{"ID":"9a7806061c88ada191ed06f989cc3dac","priority":1}]}`, string(b)) diff --git a/sts.go b/sts.go index b06456512da..94b5666ecbe 100644 --- a/sts.go +++ b/sts.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "github.com/hashicorp/go-retryablehttp" @@ -80,7 +80,7 @@ func fetchSTSCredentials(stsConfig *SecurityTokenConfiguration) (string, error) } var respBody []byte - respBody, err = ioutil.ReadAll(resp.Body) + respBody, err = io.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("failed to read response body: %w", err) } diff --git a/tunnel_routes_test.go b/tunnel_routes_test.go index 81ab39e2de7..b9583bd115d 100644 --- a/tunnel_routes_test.go +++ b/tunnel_routes_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -150,7 +150,7 @@ func TestUpdateTunnelRoute(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - _, err := ioutil.ReadAll(r.Body) + _, err := io.ReadAll(r.Body) if err != nil { panic(err) } diff --git a/tunnel_virtual_networks_test.go b/tunnel_virtual_networks_test.go index 91818aa4e4e..2e6affdd23a 100644 --- a/tunnel_virtual_networks_test.go +++ b/tunnel_virtual_networks_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -108,7 +108,7 @@ func TestUpdateTunnelVirtualNetwork(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - _, err := ioutil.ReadAll(r.Body) + _, err := io.ReadAll(r.Body) if err != nil { panic(err) } diff --git a/universal_ssl_test.go b/universal_ssl_test.go index 6c6c475b4dc..3b2e16922c3 100644 --- a/universal_ssl_test.go +++ b/universal_ssl_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -45,7 +45,7 @@ func TestEditUniversalSSLSetting(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } @@ -131,7 +131,7 @@ func TestUpdateSSLCertificatePackValidationMethod(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } diff --git a/url_normalization_settings_test.go b/url_normalization_settings_test.go index 0ad7f67a4b8..6a6ac11167e 100644 --- a/url_normalization_settings_test.go +++ b/url_normalization_settings_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -47,7 +47,7 @@ func TestUpdateURLNormalizationSettings(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } diff --git a/user_test.go b/user_test.go index 661c9843f64..d3d70903d86 100644 --- a/user_test.go +++ b/user_test.go @@ -3,12 +3,11 @@ package cloudflare import ( "context" "fmt" + "io" "net/http" "testing" "time" - "io/ioutil" - "github.com/stretchr/testify/assert" ) @@ -72,7 +71,7 @@ func TestUser_UpdateUser(t *testing.T) { mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) { assert.JSONEq(t, `{"country":"US","first_name":"John","username":"cfuser12345","email":"user@example.com", diff --git a/waf_test.go b/waf_test.go index 88cec476024..63bc2b034a3 100644 --- a/waf_test.go +++ b/waf_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strconv" @@ -197,7 +197,7 @@ func TestUpdateWAFPackage(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } @@ -448,7 +448,7 @@ func TestUpdateWAFGroup(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } @@ -732,7 +732,7 @@ func TestUpdateWAFRule(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } diff --git a/workers.go b/workers.go index dc1b13372e2..3b37de90d1a 100644 --- a/workers.go +++ b/workers.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "mime" "mime/multipart" "net/http" @@ -449,7 +448,7 @@ func (api *API) downloadWorkerWithName(ctx context.Context, scriptName string) ( if err != nil { return r, fmt.Errorf("could not get multipart response body: %w", err) } - mimePartBody, err := ioutil.ReadAll(mimePart) + mimePartBody, err := io.ReadAll(mimePart) if err != nil { return r, fmt.Errorf("could not read multipart response body: %w", err) } diff --git a/workers_test.go b/workers_test.go index fcf7d4f4566..434bb065d16 100644 --- a/workers_test.go +++ b/workers_test.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "mime/multipart" "net/http" "strings" @@ -247,7 +247,7 @@ func getFormValue(r *http.Request, key string) ([]byte, error) { if err != nil { return nil, err } - return ioutil.ReadAll(file) + return io.ReadAll(file) } return nil, fmt.Errorf("no value found for key %v", key) @@ -1228,7 +1228,7 @@ func TestWorkers_ListWorkerBindingsMultiScript(t *testing.T) { assert.Equal(t, "MY_WASM", res.BindingList[1].Name) wasmBinding := res.BindingList[1].Binding.(WorkerWebAssemblyBinding) - wasmModuleContent, err := ioutil.ReadAll(wasmBinding.Module) + wasmModuleContent, err := io.ReadAll(wasmBinding.Module) assert.NoError(t, err) assert.Equal(t, []byte("mock multi-script wasm"), wasmModuleContent) assert.Equal(t, WorkerWebAssemblyBindingType, res.BindingList[1].Binding.Type()) diff --git a/zone_cache_variants_test.go b/zone_cache_variants_test.go index e1522a63ef2..315d2d9221a 100644 --- a/zone_cache_variants_test.go +++ b/zone_cache_variants_test.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -71,7 +71,7 @@ func TestZoneCacheVariantsUpdate(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method) - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) defer r.Body.Close() if assert.NoError(t, err) {