-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (50 loc) · 1.22 KB
/
main.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
50
51
52
53
54
55
56
57
58
//go:build js && wasm
// +build js,wasm
package main
import (
"encoding/json"
"github.com/alswl/dingmark/pkg/services"
"github.com/alswl/dingmark/pkg/tokens"
robot "github.com/alswl/dingmark/third_party/go-ding-robot"
"syscall/js"
)
func init() {
// https://corsproxy.github.io/
// did not support POST
// https://cors.sh
// token is required
robot.Webhook = "https://proxy.cors.sh/https://oapi.dingtalk.com/robot/send"
//https://cors-proxy.htmldriven.com/
//robot.Webhook = "https://cors-proxy.htmldriven.com/?url=https://oapi.dingtalk.com/robot/send"
}
func jsFunc(this js.Value, args []js.Value) interface{} {
if len(args) != 4 {
return js.ValueOf("args length must be 4")
}
token := args[0]
secret := args[1]
title := args[2]
text := args[3]
robot.ExtendHeaders = map[string]string{
"x-cors-api-key": tokens.CORSDotSH,
}
resp, err := services.SendMarkdown(
token.String(),
secret.String(),
title.String(),
text.String(),
)
if err != nil {
return js.ValueOf(err.Error())
}
if resp == nil {
return js.ValueOf(nil)
}
marshal, err := json.Marshal(resp)
return js.ValueOf(string(marshal))
}
func main() {
done := make(chan int, 0)
js.Global().Set("SendMarkdown", js.FuncOf(jsFunc))
<-done
}