代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"net/http"
"strconv"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
)
// curl -X GET -H "Cache-Control: no-cache" "http://localhost:1323/start"
// curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
// "data":[
// {"name":"1"},
// {"name":"2"},
// {"name":"3"},
// {"name":"4"},
// {"name":"5"}
// ]
// }' "http://localhost:1323/"
var (
// MaxWorker = os.Getenv("MAX_WORKERS")
// MaxQueue = os.Getenv("MAX_QUEUE")
MaxWorker = "10"
MaxQueue = "10"
MaxLength int64 = 1024
)
// A buffered channel that we can send work requests on.
var JobQueue chan Job
func init() {
maxQueue, _ := strconv.Atoi(MaxQueue)
JobQueue = make(chan Job, maxQueue)
}
func main() {
e := echo.New()
e.Get("/start", func(c echo.Context) error {
maxWorker, _ := strconv.Atoi(MaxWorker)
dispatcher := NewDispatcher(maxWorker)
dispatcher.Run()
fmt.Println("start!")
return c.String(http.StatusOK, "Start!!")
})
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "OK!")
})
e.POST("/", func(c echo.Context) error {
content := &PayloadCollection{}
if err := c.Bind(content); err != nil {
return err
}
// Go through each payload and queue items individually to be posted to S3
for _, payload := range content.Payloads {
// let's create a job with the payload
work := Job{Payload: payload}
// Push the work onto the queue.
JobQueue <- work
}
return c.String(http.StatusOK, "CARETE!")
})
e.Run(standard.New(":1323"))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。