Skip to content

Commit

Permalink
webhooks: remove go1.12 support
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Feb 14, 2022
1 parent d0f8402 commit 9f7a7e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 67 deletions.
24 changes: 24 additions & 0 deletions webhooks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package slack

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -35,3 +38,24 @@ func PostWebhookCustomHTTP(url string, httpClient *http.Client, msg *WebhookMess
func PostWebhookContextCustomHTTP(ctx context.Context, url string, httpClient *http.Client, msg *WebhookMessage) error {
return PostWebhookCustomHTTPContext(ctx, url, httpClient, msg)
}

func PostWebhookCustomHTTPContext(ctx context.Context, url string, httpClient *http.Client, msg *WebhookMessage) error {
raw, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("marshal failed: %w", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(raw))
if err != nil {
return fmt.Errorf("failed new request: %w", err)
}
req.Header.Set("Content-Type", "application/json")

resp, err := httpClient.Do(req)
if err != nil {
return fmt.Errorf("failed to post webhook: %w", err)
}
defer resp.Body.Close()

return checkStatusCode(resp, discard{})
}
34 changes: 0 additions & 34 deletions webhooks_go112.go

This file was deleted.

33 changes: 0 additions & 33 deletions webhooks_go113.go

This file was deleted.

0 comments on commit 9f7a7e3

Please sign in to comment.