chromeworker/proxyserver/callback.go

54 lines
1.2 KiB
Go

package main
import (
"fmt"
"log"
"github.com/474420502/requests"
)
// CallbackServer 处理回调客户端
func CallbackServer(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)
_, 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"
}
}
}
// 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"
}
}
}