Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
|
10f971da0a | |
|
f4a72221e5 | |
|
948a6b63d2 |
|
@ -0,0 +1,28 @@
|
||||||
|
羽量级回调任务,直接集成到程序中
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go get -u gitea.cdlsxd.cn/self-tools/l_notify
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
```go
|
||||||
|
notify := &l_notify.Notify{
|
||||||
|
Request: &l_request.Request{
|
||||||
|
Method: "POST",
|
||||||
|
Url: reqUrl,
|
||||||
|
Json: r.RequestBody,
|
||||||
|
Headers: r.header,
|
||||||
|
},
|
||||||
|
DelayList: []int32{3, 6, 8, 5, 8}, //[30,60,120...]:从前往后分别延迟30秒,60秒,120秒...推送,[60]:每隔60秒推送一次
|
||||||
|
ResultHandle: func(r l_request.Response, e error) (stop bool) {
|
||||||
|
//do something
|
||||||
|
return
|
||||||
|
},//推送结果处理函数,stop为true时表示停止推送
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module gitea.cdlsxd.cn/self-tools/l_notify
|
module gitea.cdlsxd.cn/self-tools/l_notify
|
||||||
|
|
||||||
go 1.23.6
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/self-tools/l_request v1.0.4 // indirect
|
gitea.cdlsxd.cn/self-tools/l_request v1.0.4 // indirect
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (n *Notify) next() {
|
||||||
}
|
}
|
||||||
time := "@every " + fmt.Sprintf("%ds", n.DelayList[n.i])
|
time := "@every " + fmt.Sprintf("%ds", n.DelayList[n.i])
|
||||||
n.currenEntry, _ = n.cron.AddFunc(time, func() {
|
n.currenEntry, _ = n.cron.AddFunc(time, func() {
|
||||||
e := n.ResultHandle(n.DoFuc())
|
e := n.ResultHandle(n.Request.Send())
|
||||||
if n.isLoop {
|
if n.isLoop {
|
||||||
//循环推送直到成功
|
//循环推送直到成功
|
||||||
if e {
|
if e {
|
||||||
|
|
Loading…
Reference in New Issue