1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
common.go 1.64 KB
Copy Edit Raw Blame History
kzangv authored 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.7

Search