diff --git a/chat.go b/chat.go index 916d05a93..18f8e933d 100644 --- a/chat.go +++ b/chat.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "encoding/json" - "io/ioutil" + "io" "net/http" "net/url" "regexp" @@ -226,11 +226,11 @@ func (api *Client) SendMessageContext(ctx context.Context, channelID string, opt } if api.Debug() { - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) if err != nil { return "", "", "", err } - req.Body = ioutil.NopCloser(bytes.NewBuffer(reqBody)) + req.Body = io.NopCloser(bytes.NewBuffer(reqBody)) api.Debugf("Sending request: %s", redactToken(reqBody)) } diff --git a/chat_test.go b/chat_test.go index ee93bddff..917ff965e 100644 --- a/chat_test.go +++ b/chat_test.go @@ -3,7 +3,7 @@ package slack import ( "bytes" "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -216,7 +216,7 @@ func TestPostMessage(t *testing.T) { t.Run(name, func(t *testing.T) { http.DefaultServeMux = new(http.ServeMux) http.HandleFunc(test.endpoint, func(rw http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { t.Errorf("unexpected error: %v", err) return @@ -242,7 +242,7 @@ func TestPostMessageWithBlocksWhenMsgOptionResponseURLApplied(t *testing.T) { http.DefaultServeMux = new(http.ServeMux) http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { t.Errorf("unexpected error: %v", err) return @@ -270,7 +270,7 @@ func TestPostMessageWithBlocksWhenMsgOptionResponseURLApplied(t *testing.T) { func TestPostMessageWhenMsgOptionReplaceOriginalApplied(t *testing.T) { http.DefaultServeMux = new(http.ServeMux) http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { t.Errorf("unexpected error: %v", err) return @@ -297,7 +297,7 @@ func TestPostMessageWhenMsgOptionReplaceOriginalApplied(t *testing.T) { func TestPostMessageWhenMsgOptionDeleteOriginalApplied(t *testing.T) { http.DefaultServeMux = new(http.ServeMux) http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { t.Errorf("unexpected error: %v", err) return diff --git a/examples/dialog/dialog.go b/examples/dialog/dialog.go index 4b4d6ab18..dc0d431c3 100644 --- a/examples/dialog/dialog.go +++ b/examples/dialog/dialog.go @@ -2,7 +2,7 @@ package main import ( "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -26,7 +26,7 @@ func handler(w http.ResponseWriter, r *http.Request) { // Read request body defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusInternalServerError) log.Printf("[ERROR] Fail to read request body: %v", err) diff --git a/examples/eventsapi/events.go b/examples/eventsapi/events.go index 25049ad07..b3bb70ab4 100644 --- a/examples/eventsapi/events.go +++ b/examples/eventsapi/events.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" @@ -18,7 +18,7 @@ func main() { signingSecret := os.Getenv("SLACK_SIGNING_SECRET") http.HandleFunc("/events-endpoint", func(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return diff --git a/examples/modal/modal.go b/examples/modal/modal.go index 155f2f714..13115a826 100644 --- a/examples/modal/modal.go +++ b/examples/modal/modal.go @@ -15,7 +15,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/slack-go/slack" @@ -95,13 +95,13 @@ func verifySigningSecret(r *http.Request) error { return err } - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { fmt.Println(err.Error()) return err } // Need to use r.Body again when unmarshalling SlashCommand and InteractionCallback - r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + r.Body = io.NopCloser(bytes.NewBuffer(body)) verifier.Write(body) if err = verifier.Ensure(); err != nil { diff --git a/examples/slash/slash.go b/examples/slash/slash.go index c70c865ff..e35ab10a8 100644 --- a/examples/slash/slash.go +++ b/examples/slash/slash.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net/http" "github.com/slack-go/slack" @@ -27,7 +26,7 @@ func main() { return } - r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &verifier)) + r.Body = io.NopCloser(io.TeeReader(r.Body, &verifier)) s, err := slack.SlashCommandParse(r) if err != nil { w.WriteHeader(http.StatusInternalServerError) diff --git a/examples/workflow_step/handler.go b/examples/workflow_step/handler.go index b25a5be42..d0eee101f 100644 --- a/examples/workflow_step/handler.go +++ b/examples/workflow_step/handler.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -25,7 +25,7 @@ func handleMyWorkflowStep(w http.ResponseWriter, r *http.Request) { } // see: https://github.com/slack-go/slack/blob/master/examples/eventsapi/events.go - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -88,7 +88,7 @@ func handleInteraction(w http.ResponseWriter, r *http.Request) { return } - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return diff --git a/examples/workflow_step/middleware.go b/examples/workflow_step/middleware.go index 0684e50d6..6fe826910 100644 --- a/examples/workflow_step/middleware.go +++ b/examples/workflow_step/middleware.go @@ -2,20 +2,20 @@ package main import ( "bytes" - "io/ioutil" + "io" "net/http" "github.com/slack-go/slack" ) func (v *SecretsVerifierMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return } r.Body.Close() - r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + r.Body = io.NopCloser(bytes.NewBuffer(body)) sv, err := slack.NewSecretsVerifier(r.Header, appCtx.config.signingSecret) if err != nil { diff --git a/files_test.go b/files_test.go index 59afc1c4b..1df46aa6e 100644 --- a/files_test.go +++ b/files_test.go @@ -3,7 +3,7 @@ package slack import ( "bytes" "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -44,7 +44,7 @@ func (h *fileCommentHandler) handler(w http.ResponseWriter, r *http.Request) { type mockHTTPClient struct{} func (m *mockHTTPClient) Do(*http.Request) (*http.Response, error) { - return &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewBufferString(`OK`))}, nil + return &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewBufferString(`OK`))}, nil } func TestSlack_GetFile(t *testing.T) { diff --git a/misc.go b/misc.go index 7e5a8d54a..a25afb65e 100644 --- a/misc.go +++ b/misc.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "mime" "mime/multipart" "net/http" @@ -127,7 +126,7 @@ func jsonReq(ctx context.Context, endpoint string, body interface{}) (req *http. } func parseResponseBody(body io.ReadCloser, intf interface{}, d Debug) error { - response, err := ioutil.ReadAll(body) + response, err := io.ReadAll(body) if err != nil { return err } @@ -316,7 +315,7 @@ func newJSONParser(dst interface{}) responseParser { func newTextParser(dst interface{}) responseParser { return func(resp *http.Response) error { - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/reminders_test.go b/reminders_test.go index 25291b543..09dd6a096 100644 --- a/reminders_test.go +++ b/reminders_test.go @@ -2,7 +2,7 @@ package slack import ( "bytes" - "io/ioutil" + "io" "net/http" "reflect" "testing" @@ -185,7 +185,7 @@ func (m *mockRemindersListHTTPClient) Do(*http.Request) (*http.Response, error) ] }` - return &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewBufferString(responseString))}, nil + return &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewBufferString(responseString))}, nil } func TestSlack_ListReminders(t *testing.T) { diff --git a/slacktest/handlers.go b/slacktest/handlers.go index b4a0227f3..22c1680f6 100644 --- a/slacktest/handlers.go +++ b/slacktest/handlers.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -46,7 +46,7 @@ type GroupConversationResponse struct { } func (sts *Server) conversationsInfoHandler(w http.ResponseWriter, r *http.Request) { - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("error reading body: %s", err.Error()) log.Printf(msg) @@ -126,7 +126,7 @@ func reactionAddHandler(w http.ResponseWriter, _ *http.Request) { // handle chat.postMessage func (sts *Server) postMessageHandler(w http.ResponseWriter, r *http.Request) { serverAddr := r.Context().Value(ServerBotHubNameContextKey).(string) - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("error reading body: %s", err.Error()) log.Printf(msg) @@ -218,7 +218,7 @@ func (sts *Server) postMessageHandler(w http.ResponseWriter, r *http.Request) { // RTMConnectHandler generates a valid connection func RTMConnectHandler(w http.ResponseWriter, r *http.Request) { - _, err := ioutil.ReadAll(r.Body) + _, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("Error reading body: %s", err.Error()) log.Printf(msg) @@ -248,7 +248,7 @@ func RTMConnectHandler(w http.ResponseWriter, r *http.Request) { } func rtmStartHandler(w http.ResponseWriter, r *http.Request) { - _, err := ioutil.ReadAll(r.Body) + _, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("Error reading body: %s", err.Error()) log.Printf(msg) diff --git a/users_test.go b/users_test.go index 5ba915995..eedfd2d60 100644 --- a/users_test.go +++ b/users_test.go @@ -8,7 +8,6 @@ import ( "image/draw" "image/png" "io" - "io/ioutil" "net/http" "os" "reflect" @@ -556,7 +555,7 @@ func setUserPhotoHandler(wantBytes []byte, wantParams UserSetPhotoParams) http.H httpTestErrReply(w, true, fmt.Sprintf("failed to open uploaded file: %+v", err)) return } - gotBytes, err := ioutil.ReadAll(file) + gotBytes, err := io.ReadAll(file) if err != nil { httpTestErrReply(w, true, fmt.Sprintf("failed to read uploaded file: %+v", err)) return @@ -577,7 +576,7 @@ func createUserPhoto(t *testing.T) (*os.File, []byte, func()) { photo := image.NewRGBA(image.Rect(0, 0, 64, 64)) draw.Draw(photo, photo.Bounds(), image.Black, image.ZP, draw.Src) - f, err := ioutil.TempFile(os.TempDir(), "profile.png") + f, err := os.CreateTemp(os.TempDir(), "profile.png") if err != nil { t.Fatalf("failed to create test photo: %+v\n", err) } diff --git a/webhooks.go b/webhooks.go index 8fc149d90..5a854f38b 100644 --- a/webhooks.go +++ b/webhooks.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" ) @@ -57,7 +56,7 @@ func PostWebhookCustomHTTPContext(ctx context.Context, url string, httpClient *h return fmt.Errorf("failed to post webhook: %w", err) } defer func() { - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() }()