Skip to content

Commit

Permalink
Replace all usage of ioutil.ReadAll (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoodhouse93 authored Jul 28, 2024
1 parent d98ca77 commit 9f8e4dc
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 56 deletions.
4 changes: 2 additions & 2 deletions endpoints/adminaudit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package endpoints
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/admingeneratelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions endpoints/adminssoproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions endpoints/adminusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions endpoints/adminusersfactors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions endpoints/factors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package endpoints
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package endpoints

import (
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/magiclink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/reauthenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package endpoints

import (
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions endpoints/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 4 additions & 3 deletions endpoints/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package endpoints

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
)
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 9f8e4dc

Please sign in to comment.