From 9f8e4dca798b7c2cc319cad0e33b9577ffe85a6c Mon Sep 17 00:00:00 2001 From: Kieron Woodhouse Date: Sun, 28 Jul 2024 16:10:04 +0100 Subject: [PATCH] Replace all usage of ioutil.ReadAll (#9) --- endpoints/adminaudit.go | 4 ++-- endpoints/admingeneratelink.go | 4 ++-- endpoints/adminssoproviders.go | 12 ++++++------ endpoints/adminusers.go | 12 ++++++------ endpoints/adminusersfactors.go | 8 ++++---- endpoints/factors.go | 10 +++++----- endpoints/health.go | 4 ++-- endpoints/invite.go | 4 ++-- endpoints/logout.go | 4 ++-- endpoints/magiclink.go | 4 ++-- endpoints/otp.go | 4 ++-- endpoints/reauthenticate.go | 4 ++-- endpoints/recover.go | 4 ++-- endpoints/saml.go | 7 ++++--- endpoints/settings.go | 4 ++-- endpoints/signup.go | 4 ++-- endpoints/sso.go | 4 ++-- endpoints/token.go | 4 ++-- endpoints/user.go | 6 +++--- endpoints/verify.go | 6 +++--- 20 files changed, 57 insertions(+), 56 deletions(-) diff --git a/endpoints/adminaudit.go b/endpoints/adminaudit.go index 2e4de55..ce405e4 100644 --- a/endpoints/adminaudit.go +++ b/endpoints/adminaudit.go @@ -3,7 +3,7 @@ package endpoints import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strconv" @@ -58,7 +58,7 @@ func (c *Client) AdminAudit(req types.AdminAuditRequest) (*types.AdminAuditRespo defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/admingeneratelink.go b/endpoints/admingeneratelink.go index f454a2c..e290aaf 100644 --- a/endpoints/admingeneratelink.go +++ b/endpoints/admingeneratelink.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -79,7 +79,7 @@ func (c *Client) AdminGenerateLink(req types.AdminGenerateLinkRequest) (*types.A defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/adminssoproviders.go b/endpoints/adminssoproviders.go index 83fd9f5..18c9859 100644 --- a/endpoints/adminssoproviders.go +++ b/endpoints/adminssoproviders.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -28,7 +28,7 @@ func (c *Client) AdminListSSOProviders() (*types.AdminListSSOProvidersResponse, defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -65,7 +65,7 @@ func (c *Client) AdminCreateSSOProvider(req types.AdminCreateSSOProviderRequest) defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -97,7 +97,7 @@ func (c *Client) AdminGetSSOProvider(req types.AdminGetSSOProviderRequest) (*typ defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -134,7 +134,7 @@ func (c *Client) AdminUpdateSSOProvider(req types.AdminUpdateSSOProviderRequest) defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -167,7 +167,7 @@ func (c *Client) AdminDeleteSSOProvider(req types.AdminDeleteSSOProviderRequest) defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/adminusers.go b/endpoints/adminusers.go index 4729a82..3b55464 100644 --- a/endpoints/adminusers.go +++ b/endpoints/adminusers.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -33,7 +33,7 @@ func (c *Client) AdminCreateUser(req types.AdminCreateUserRequest) (*types.Admin defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -65,7 +65,7 @@ func (c *Client) AdminListUsers() (*types.AdminListUsersResponse, error) { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -98,7 +98,7 @@ func (c *Client) AdminGetUser(req types.AdminGetUserRequest) (*types.AdminGetUse defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -136,7 +136,7 @@ func (c *Client) AdminUpdateUser(req types.AdminUpdateUserRequest) (*types.Admin defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -169,7 +169,7 @@ func (c *Client) AdminDeleteUser(req types.AdminDeleteUserRequest) error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/adminusersfactors.go b/endpoints/adminusersfactors.go index 8c2e0a8..a8e4715 100644 --- a/endpoints/adminusersfactors.go +++ b/endpoints/adminusersfactors.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -28,7 +28,7 @@ func (c *Client) AdminListUserFactors(req types.AdminListUserFactorsRequest) (*t defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -73,7 +73,7 @@ func (c *Client) AdminUpdateUserFactor(req types.AdminUpdateUserFactorRequest) ( defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -107,7 +107,7 @@ func (c *Client) AdminDeleteUserFactor(req types.AdminDeleteUserFactorRequest) e defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/factors.go b/endpoints/factors.go index 5205b33..4e4d010 100644 --- a/endpoints/factors.go +++ b/endpoints/factors.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "time" @@ -40,7 +40,7 @@ func (c *Client) EnrollFactor(req types.EnrollFactorRequest) (*types.EnrollFacto defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -71,7 +71,7 @@ func (c *Client) ChallengeFactor(req types.ChallengeFactorRequest) (*types.Chall defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -116,7 +116,7 @@ func (c *Client) VerifyFactor(req types.VerifyFactorRequest) (*types.VerifyFacto defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -148,7 +148,7 @@ func (c *Client) UnenrollFactor(req types.UnenrollFactorRequest) (*types.Unenrol defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/health.go b/endpoints/health.go index ef32960..57a8b1e 100644 --- a/endpoints/health.go +++ b/endpoints/health.go @@ -3,7 +3,7 @@ package endpoints import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -27,7 +27,7 @@ func (c *Client) HealthCheck() (*types.HealthCheckResponse, error) { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/invite.go b/endpoints/invite.go index 5ed7223..1f428e7 100644 --- a/endpoints/invite.go +++ b/endpoints/invite.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -34,7 +34,7 @@ func (c *Client) Invite(req types.InviteRequest) (*types.InviteResponse, error) defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/logout.go b/endpoints/logout.go index f40d336..258a687 100644 --- a/endpoints/logout.go +++ b/endpoints/logout.go @@ -2,7 +2,7 @@ package endpoints import ( "fmt" - "io/ioutil" + "io" "net/http" ) @@ -27,7 +27,7 @@ func (c *Client) Logout() error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/magiclink.go b/endpoints/magiclink.go index 0b488ed..10c8feb 100644 --- a/endpoints/magiclink.go +++ b/endpoints/magiclink.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -39,7 +39,7 @@ func (c *Client) Magiclink(req types.MagiclinkRequest) error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/otp.go b/endpoints/otp.go index 7a7657d..b7332ac 100644 --- a/endpoints/otp.go +++ b/endpoints/otp.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -36,7 +36,7 @@ func (c *Client) OTP(req types.OTPRequest) error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/reauthenticate.go b/endpoints/reauthenticate.go index 7298d3f..abcd531 100644 --- a/endpoints/reauthenticate.go +++ b/endpoints/reauthenticate.go @@ -2,7 +2,7 @@ package endpoints import ( "fmt" - "io/ioutil" + "io" "net/http" ) @@ -26,7 +26,7 @@ func (c *Client) Reauthenticate() error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/recover.go b/endpoints/recover.go index a01e800..cd12332 100644 --- a/endpoints/recover.go +++ b/endpoints/recover.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -36,7 +36,7 @@ func (c *Client) Recover(req types.RecoverRequest) error { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/saml.go b/endpoints/saml.go index a7923d7..206e553 100644 --- a/endpoints/saml.go +++ b/endpoints/saml.go @@ -2,7 +2,7 @@ package endpoints import ( "fmt" - "io/ioutil" + "io" "net/http" "net/url" ) @@ -29,14 +29,14 @@ func (c *Client) SAMLMetadata() ([]byte, error) { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } return nil, fmt.Errorf("response status code %d: %s", resp.StatusCode, fullBody) } - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } // POST /sso/saml/acs @@ -56,6 +56,7 @@ func (c *Client) SAMLMetadata() ([]byte, error) { // client using WithClient(). See the example below. // // Example: +// // c := http.Client{ // CheckRedirect: func(req *http.Request, via []*http.Request) error { // return http.ErrUseLastResponse diff --git a/endpoints/settings.go b/endpoints/settings.go index d1aedb7..d1020ea 100644 --- a/endpoints/settings.go +++ b/endpoints/settings.go @@ -3,7 +3,7 @@ package endpoints import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -27,7 +27,7 @@ func (c *Client) GetSettings() (*types.SettingsResponse, error) { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/signup.go b/endpoints/signup.go index e083699..d970119 100644 --- a/endpoints/signup.go +++ b/endpoints/signup.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/google/uuid" @@ -35,7 +35,7 @@ func (c *Client) Signup(req types.SignupRequest) (*types.SignupResponse, error) defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/sso.go b/endpoints/sso.go index 78bb2dd..e72a765 100644 --- a/endpoints/sso.go +++ b/endpoints/sso.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -48,7 +48,7 @@ func (c *Client) SSO(req types.SSORequest) (*types.SSOResponse, error) { defer resp.Body.Close() if resp.StatusCode != http.StatusSeeOther { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/token.go b/endpoints/token.go index da1e225..3fa532c 100644 --- a/endpoints/token.go +++ b/endpoints/token.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -82,7 +82,7 @@ func (c *Client) Token(req types.TokenRequest) (*types.TokenResponse, error) { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/user.go b/endpoints/user.go index 8683540..d853c93 100644 --- a/endpoints/user.go +++ b/endpoints/user.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/supabase-community/gotrue-go/types" @@ -28,7 +28,7 @@ func (c *Client) GetUser() (*types.UserResponse, error) { defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -67,7 +67,7 @@ func (c *Client) UpdateUser(req types.UpdateUserRequest) (*types.UpdateUserRespo defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } diff --git a/endpoints/verify.go b/endpoints/verify.go index a29fd8e..fed1683 100644 --- a/endpoints/verify.go +++ b/endpoints/verify.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strconv" @@ -59,7 +59,7 @@ func (c *Client) Verify(req types.VerifyRequest) (*types.VerifyResponse, error) defer resp.Body.Close() if resp.StatusCode != http.StatusSeeOther { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) } @@ -140,7 +140,7 @@ func (c *Client) VerifyForUser(req types.VerifyForUserRequest) (*types.VerifyFor defer resp.Body.Close() if resp.StatusCode != http.StatusSeeOther { - fullBody, err := ioutil.ReadAll(resp.Body) + fullBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("response status code %d", resp.StatusCode) }