-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathwebhookTest.go
executable file
·54 lines (45 loc) · 1.13 KB
/
webhookTest.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
package web
import (
"encoding/json"
"net/http"
"github.com/jeessy2/ddns-go/v6/config"
"github.com/jeessy2/ddns-go/v6/util"
)
func WebhookTest(writer http.ResponseWriter, request *http.Request) {
var data struct {
URL string `json:"URL"`
RequestBody string `json:"RequestBody"`
Headers string `json:"Headers"`
}
err := json.NewDecoder(request.Body).Decode(&data)
if err != nil {
util.Log("数据解析失败, 请刷新页面重试")
return
}
url := data.URL
requestBody := data.RequestBody
headers := data.Headers
if url == "" {
util.Log("请输入Webhook的URL")
return
}
var domains = make([]*config.Domain, 1)
domains[0] = &config.Domain{}
domains[0].DomainName = "example.com"
domains[0].SubDomain = "test"
domains[0].UpdateStatus = config.UpdatedSuccess
fakeDomains := &config.Domains{
Ipv4Addr: "127.0.0.1",
Ipv4Domains: domains,
Ipv6Addr: "::1",
Ipv6Domains: domains,
}
fakeConfig := &config.Config{
Webhook: config.Webhook{
WebhookURL: url,
WebhookRequestBody: requestBody,
WebhookHeaders: headers,
},
}
config.ExecWebhook(fakeDomains, fakeConfig)
}