-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sender | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"watchAlert/pkg/utils/http" | ||
) | ||
|
||
type DingResponseMsg struct { | ||
Code int `json:"errcode"` | ||
Msg string `json:"errmsg"` | ||
} | ||
|
||
func SendToDingDing(hook, msg string) error { | ||
cardContentByte := bytes.NewReader([]byte(msg)) | ||
res, err := http.Post(nil, hook, cardContentByte) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// 读取响应体内容 | ||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return errors.New(fmt.Sprintf("Error reading Dingding response body: %s", err.Error())) | ||
} | ||
|
||
var response DingResponseMsg | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
return errors.New(fmt.Sprintf("Error unmarshalling Dingding response: %s", err.Error())) | ||
} | ||
if response.Code != 0 { | ||
return errors.New(response.Msg) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sender | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"watchAlert/pkg/utils/http" | ||
) | ||
|
||
type FeiShuResponseMsg struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
} | ||
|
||
func SendToFeiShu(hook, msg string) error { | ||
cardContentByte := bytes.NewReader([]byte(msg)) | ||
res, err := http.Post(nil, hook, cardContentByte) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// 读取响应体内容 | ||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return errors.New(fmt.Sprintf("Error reading Feishu response body: %s, msg: %s", string(body), err.Error())) | ||
} | ||
|
||
var response FeiShuResponseMsg | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
return errors.New(fmt.Sprintf("Error unmarshalling Feishu response: %s", err.Error())) | ||
} | ||
if response.Code != 0 { | ||
return errors.New(response.Msg) | ||
} | ||
|
||
return nil | ||
} |