diff --git a/proxyserver/callback.go b/proxyserver/callback.go index dd565cf..6000404 100644 --- a/proxyserver/callback.go +++ b/proxyserver/callback.go @@ -19,7 +19,7 @@ func CallbackServer(task *Task) { defer task.lock.Unlock() if callback, ok := task.data["callback"]; ok { cburl := callback.(string) - log.Println(cburl) + // log.Println(cburl) _, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute() if err != nil { log.Println(err) diff --git a/proxyserver/router.go b/proxyserver/router.go index 29c6bd2..2c70a39 100644 --- a/proxyserver/router.go +++ b/proxyserver/router.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "net/http" - "runtime" "time" "github.com/bwmarrin/snowflake" @@ -70,9 +69,12 @@ func PutTask(c *gin.Context) { data := NewTask() now := time.Now() tid := snowNode.Generate().Base64() + label := c.PostForm("label") data.Store("taskid", tid) data.Store("url", u) data.Store("ts", now.UnixNano()) + data.Store("label", label) + if callback := c.PostForm("callback"); callback != "" { data.Store("callback", callback) } @@ -88,10 +90,7 @@ func PutTask(c *gin.Context) { // ContentTask 把一条任务放入队列 func ContentTask(c *gin.Context) { - pc, _, _, _ := runtime.Caller(0) - log.Println(runtime.FuncForPC(pc).Name()) var err error - tid, ok := c.GetPostForm("taskid") if !ok { c.JSON(http.StatusOK, Response{Code: 404, Message: "taskid is not set"}) @@ -104,7 +103,10 @@ func ContentTask(c *gin.Context) { task.Store("status", "ready") readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化 c.JSON(200, Response{Code: 200, Data: task}) - log.Println("start callback") + // log.Println("start callback") + if label, ok := task.Load("label"); ok { + log.Println(label.(string), tid) + } go CallbackServer(task) return } diff --git a/proxyserver/utils.go b/proxyserver/utils.go new file mode 100644 index 0000000..bb56a79 --- /dev/null +++ b/proxyserver/utils.go @@ -0,0 +1,12 @@ +package main + +import ( + "log" + "runtime" +) + +// 打印当前函数名 +func logFunctionName() { + pc, _, _, _ := runtime.Caller(0) + log.Println(runtime.FuncForPC(pc).Name()) +}