From 2f85da86f245b159bc39ace61ceb8f07815a07e4 Mon Sep 17 00:00:00 2001 From: engigu Date: Mon, 8 Jan 2024 23:41:14 +0800 Subject: [PATCH] fix: add request timeout --- pkg/message/custom.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/message/custom.go b/pkg/message/custom.go index ffacb06..ac365e3 100644 --- a/pkg/message/custom.go +++ b/pkg/message/custom.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "net/http" + "time" ) type CustomWebhook struct { @@ -11,8 +12,12 @@ type CustomWebhook struct { Body string } +var Client = &http.Client{ + Timeout: 8 * time.Second, +} + func (cw *CustomWebhook) Request(url string, msg string) ([]byte, error) { - resp, err := http.Post(url, "application/json", bytes.NewBuffer([]byte(msg))) + resp, err := Client.Post(url, "application/json", bytes.NewBuffer([]byte(msg))) if err != nil { return nil, err }