-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
49 lines (44 loc) · 1.04 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
"github.com/yangwenmai/pg/dinghook"
)
// RenderError render error to json
func RenderError(ctx *fasthttp.RequestCtx, err interface{}) {
o := err
if err1, ok := err.(error); ok {
o = err1.Error()
}
result := map[string]interface{}{
"success": false,
"error": o,
}
bs, err := json.Marshal(result)
if err != nil {
panic(err)
}
ctx.Logger().Printf("response: %s", string(bs))
ctx.Write(bs)
}
// RenderJSON render to json
func RenderJSON(ctx *fasthttp.RequestCtx, data interface{}) {
result := map[string]interface{}{
"success": true,
"data": data,
}
bs, err := json.Marshal(result)
if err != nil {
panic(err)
}
ctx.Logger().Printf("response: %s", string(bs))
ctx.Write(bs)
}
// SendDinghook 钉钉发送信息
func SendDinghook(dingAccessToken string, title string, content string) {
fmt.Println("SendDinghook...")
ding := dinghook.Ding{AccessToken: dingAccessToken}
markdown := dinghook.Markdown{Title: title, Content: content}
ding.Send(markdown)
}