package main import ( "log" "net/http" "runtime/debug" "github.com/gin-gonic/gin" ) 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) }