Skip to content

Commit

Permalink
use bytes new reader directly
Browse files Browse the repository at this point in the history
  • Loading branch information
liweiyi88 committed Mar 25, 2023
1 parent aac2f8a commit a03c1ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
4 changes: 2 additions & 2 deletions notifier/slack/slack.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package slack

import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"strings"

"github.com/liweiyi88/onedump/jobresult"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ func (slack *Slack) Notify(results []*jobresult.JobResult) error {
return fmt.Errorf("failed to marshal slack message, err: %v", err)
}

bytesReader := strings.NewReader(string(data))
bytesReader := bytes.NewReader(data)

client := &http.Client{}
res, err := client.Post(slack.IncomingWebhook, "application/json", bytesReader)
Expand Down
26 changes: 0 additions & 26 deletions notifier/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,4 @@ func TestNotify(t *testing.T) {
if err == nil {
t.Error("expected error but got nil")
}

// text := &SlackMessage{
// Text: "hello my world",
// Extra: "abcd",
// }

// data, err := json.Marshal(text)
// if err != nil {
// t.Fatal(err)
// }

// bytesReader := strings.NewReader(string(data))

// client := &http.Client{}
// res, err := client.Post(incomingwebhook, "application/json", bytesReader)

// if res.StatusCode != http.StatusOK {

// body, _ := io.ReadAll(res.Body)

// fmt.Println(string(body))
// }

// if err != nil {
// t.Fatal(err)
// }
}

0 comments on commit a03c1ec

Please sign in to comment.