chromeworker/proxyserver/callback.go

54 lines
1.2 KiB
Go
Raw Permalink Normal View History

2020-11-19 11:05:32 +00:00
package main
import (
"fmt"
"log"
"github.com/474420502/requests"
)
// CallbackServer 处理回调客户端
func CallbackServer(task *Task) {
2020-11-20 07:30:52 +00:00
defer func() {
if err := recover(); err != nil {
log.Println(err)
}
}()
2020-11-19 11:05:32 +00:00
task.lock.Lock()
defer task.lock.Unlock()
if callback, ok := task.data["callback"]; ok {
cburl := callback.(string)
_, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute()
if err != nil {
log.Println(err)
task.data["error"] = fmt.Sprintf("callback url error: %s", err)
} else {
task.data["status"] = "readied"
}
}
}
2020-11-24 07:16:37 +00:00
// ErrorCallbackServer 错误处理回调客户端
func ErrorCallbackServer(task *Task) {
defer func() {
if err := recover(); err != nil {
log.Println(err)
}
}()
task.lock.Lock()
defer task.lock.Unlock()
if callback, ok := task.data["callback"]; ok {
cburl := callback.(string)
// log.Println(cburl)
_, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute()
if err != nil {
log.Println(err)
task.data["error"] = fmt.Sprintf("callback url error: %s", err)
} else {
task.data["status"] = "readied"
}
}
}