1 Star 0 Fork 0

kzangv / gsf-fof

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
kzangv 提交于 2023-02-23 11:08 . fixed
package feishu
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
type richContentItem map[string]string
type RichContentLine []richContentItem
func (m *RichContentLine) AddLink(content, href string) *RichContentLine {
*m = append(*m, richContentItem{"text": content, "tag": "a", "href": href})
return m
}
func (m *RichContentLine) AddText(content string) *RichContentLine {
*m = append(*m, richContentItem{"text": content, "tag": "text"})
return m
}
type RichContent []RichContentLine
func (m *RichContent) AddLine(v *RichContentLine) *RichContent {
*m = append(*m, *v)
return m
}
type Interface interface {
SendSimpleMsg(content string) (bool, error)
SendRichMsg(title string, content RichContent) (bool, error)
}
func post(url string, body []byte) (bool, error) {
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return false, err
}
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}
fmt.Printf("client: response body: %s\n", resBody)
return true, nil
}
func getSimpleMsg(content string) map[string]interface{} {
return map[string]interface{}{
"msg_type": "text",
"content": map[string]string{
"text": content,
},
}
}
func getRichMsg(title string, content RichContent) map[string]interface{} {
return map[string]interface{}{
"msg_type": "post",
"content": map[string]interface{}{
"post": map[string]interface{}{
"zh_cn": map[string]interface{}{
"title": title,
"content": content,
},
},
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.2.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891