From 5fb3dffd9b88ee61e9f2e7cebc2dd5ab8390d320 Mon Sep 17 00:00:00 2001 From: catatsuy Date: Sun, 14 Feb 2021 17:25:29 +0900 Subject: [PATCH] remove ioutil --- cli/cli.go | 3 +-- config/config.go | 3 +-- slack/client.go | 9 ++++----- slack/client_test.go | 8 ++++---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 6d879f4..872e73f 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "os/signal" "runtime" @@ -250,7 +249,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 } diff --git a/config/config.go b/config/config.go index 76cf33f..2edba3f 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -30,7 +29,7 @@ func NewConfig() *Config { } func (c *Config) LoadTOML(filename string) error { - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return err } diff --git a/slack/client.go b/slack/client.go index 888db5b..c6bd552 100644 --- a/slack/client.go +++ b/slack/client.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "net/url" @@ -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 } @@ -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 } @@ -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) } @@ -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 } diff --git a/slack/client_test.go b/slack/client_test.go index c04f660..3e8f1fa 100644 --- a/slack/client_test.go +++ b/slack/client_test.go @@ -3,7 +3,7 @@ package slack_test import ( "context" "encoding/json" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -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) } @@ -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) } @@ -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) }