Skip to content

Commit

Permalink
Merge pull request #14 from tranhoangvuit/chore/update-deprecated-iou…
Browse files Browse the repository at this point in the history
…til-functions

chore: update deprecated ioutil functions
  • Loading branch information
tranhoangvuit authored Aug 20, 2023
2 parents d1fd24c + 2a33eaa commit a96c50a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
13 changes: 6 additions & 7 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -21,7 +20,7 @@ func (c *Client) ListBuckets() ([]Bucket, BucketResponseError) {
}
}(res.Body)

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
Expand All @@ -41,7 +40,7 @@ func (c *Client) GetBucket(id string) (Bucket, BucketResponseError) {
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var data Bucket
var error_ BucketResponseError
err = json.Unmarshal(body, &data)
Expand Down Expand Up @@ -72,7 +71,7 @@ func (c *Client) CreateBucket(id string, options BucketOptions) (Bucket, BucketR
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var data Bucket
var error_ BucketResponseError
err = json.Unmarshal(body, &data)
Expand Down Expand Up @@ -103,7 +102,7 @@ func (c *Client) UpdateBucket(id string, options BucketOptions) (MessageResponse
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var data MessageResponse
var error_ BucketResponseError
err = json.Unmarshal(body, &data)
Expand All @@ -119,7 +118,7 @@ func (c *Client) EmptyBucket(id string) (MessageResponse, BucketResponseError) {
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var data MessageResponse
var error_ BucketResponseError
err = json.Unmarshal(body, &data)
Expand All @@ -136,7 +135,7 @@ func (c *Client) DeleteBucket(id string) (MessageResponse, BucketResponseError)
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var data MessageResponse
var error_ BucketResponseError
err = json.Unmarshal(body, &data)
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/url"
)

var version = "v0.5.6"
var version = "v0.6.9"

type Client struct {
clientError error
Expand Down
21 changes: 10 additions & 11 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -48,7 +47,7 @@ func (c *Client) UploadOrUpdateFile(bucketId string, relativePath string, data i
panic(err)
}

body_, err := ioutil.ReadAll(res.Body)
body_, err := io.ReadAll(res.Body)
var response FileUploadResponse
err = json.Unmarshal(body_, &response)

Expand Down Expand Up @@ -80,7 +79,7 @@ func (c *Client) MoveFile(bucketId string, sourceKey string, destinationKey stri
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var response FileUploadResponse
err = json.Unmarshal(body, &response)

Expand All @@ -102,7 +101,7 @@ func (c *Client) CreateSignedUrl(bucketId string, filePath string, expiresIn int
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var response SignedUrlResponse
err = json.Unmarshal(body, &response)
response.SignedURL = c.clientTransport.baseUrl.String() + response.SignedURL
Expand All @@ -123,7 +122,7 @@ func (c *Client) CreateSignedUploadUrl(bucketId string, filePath string) (Signed
return SignedUploadUrlResponse{}, err
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return SignedUploadUrlResponse{}, err
}
Expand All @@ -150,7 +149,7 @@ func (c *Client) UploadToSignedUrl(filePath string, fileBody io.Reader) (*Upload
return nil, err
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -194,7 +193,7 @@ func (c *Client) RemoveFile(bucketId string, paths []string) FileUploadResponse
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var response FileUploadResponse
err = json.Unmarshal(body, &response)
response.Data = body
Expand Down Expand Up @@ -240,7 +239,7 @@ func (c *Client) ListFiles(bucketId string, queryPath string, options FileSearch
panic(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
var response []FileObject

err = json.Unmarshal(body, &response)
Expand Down Expand Up @@ -270,7 +269,7 @@ func (c *Client) DownloadFile(bucketId string, filePath string, urlOptions ...Ur
return nil, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
return body, err
}

Expand Down Expand Up @@ -325,8 +324,8 @@ type FileUploadResponse struct {
Key string `json:"Key"`
Message string `json:"message"`
Data []byte
Code string `json:"statusCode"`
Error string `json:"error"`
Code string `json:"statusCode"`
Error string `json:"error"`
}

type SignedUrlResponse struct {
Expand Down
3 changes: 1 addition & 2 deletions test/fileupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -105,7 +104,7 @@ func TestDownloadFile(t *testing.T) {
t.Fatalf("DownloadFile failed: %v", err)
}

err = ioutil.WriteFile("book.pdf", resp, 0644)
err = os.WriteFile("book.pdf", resp, 0644)
if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
Expand Down

0 comments on commit a96c50a

Please sign in to comment.