Skip to content

Commit

Permalink
remove ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Feb 22, 2021
1 parent 312df6d commit 2c2702c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
3 changes: 1 addition & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/signal"
"runtime"
Expand Down Expand Up @@ -243,7 +242,7 @@ func (c *CLI) uploadSnippet(ctx context.Context, filename, uploadFilename, filet
}
defer reader.Close()

content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -67,7 +66,7 @@ func (c *Config) LoadEnv() error {
}

func (c *Config) LoadTOML(filename string) error {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions slack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -55,7 +54,7 @@ func NewClient(urlStr string, logger *log.Logger) (*Client, error) {
return nil, fmt.Errorf("failed to parse url: %s: %w", urlStr, err)
}

var discardLogger = log.New(ioutil.Discard, "", log.LstdFlags)
var discardLogger = log.New(io.Discard, "", log.LstdFlags)
if logger == nil {
logger = discardLogger
}
Expand All @@ -70,7 +69,7 @@ func NewClient(urlStr string, logger *log.Logger) (*Client, error) {
}

func NewClientForPostFile(logger *log.Logger) (*Client, error) {
var discardLogger = log.New(ioutil.Discard, "", log.LstdFlags)
var discardLogger = log.New(io.Discard, "", log.LstdFlags)
if logger == nil {
logger = discardLogger
}
Expand Down Expand Up @@ -116,7 +115,7 @@ func (c *Client) PostText(ctx context.Context, param *PostTextParam) error {
}

if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("failed to read res.Body and the status code of the response from slack was not 200: %w", err)
}
Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *Client) PostFile(ctx context.Context, token string, param *PostFilePara
return err
}

b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions slack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package slack_test
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestPostText_Success(t *testing.T) {
t.Fatalf("Content-Type expected %s, but %s", expectedType, contentType)
}

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestPostFile_Success(t *testing.T) {
t.Fatalf("Content-Type expected %s, but %s", expectedType, contentType)
}

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestPostFile_Success_provideFiletype(t *testing.T) {
t.Fatalf("Content-Type expected %s, but %s", expectedType, contentType)
}

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2c2702c

Please sign in to comment.