2021-04-27 10:36:08 +00:00
|
|
|
package main
|
|
|
|
|
2021-04-28 09:26:09 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"runtime/debug"
|
2021-04-27 10:36:08 +00:00
|
|
|
|
2021-04-28 09:26:09 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
2021-04-27 10:36:08 +00:00
|
|
|
|
2021-04-28 09:26:09 +00:00
|
|
|
type Response struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func responseError(c *gin.Context, err error) {
|
|
|
|
log.Println(err)
|
|
|
|
debug.PrintStack()
|
|
|
|
c.JSON(http.StatusInternalServerError, Response{
|
|
|
|
Code: http.StatusInternalServerError,
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func responseOk(c *gin.Context) {
|
|
|
|
c.JSON(http.StatusOK, Response{
|
|
|
|
Code: http.StatusOK,
|
|
|
|
Message: "ok",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var taskQueue = NewQueue()
|
|
|
|
|
|
|
|
func PostPushQueue(c *gin.Context) {
|
|
|
|
// stask := c.PostForm("task")
|
|
|
|
task := &Task{}
|
|
|
|
err := c.BindJSON(task)
|
|
|
|
if err != nil {
|
|
|
|
responseError(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
taskQueue.Push(task)
|
|
|
|
responseOk(c)
|
2021-04-27 10:36:08 +00:00
|
|
|
}
|