running_log.go 798 B

12345678910111213141516171819202122232425262728293031
  1. package base
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
  4. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  5. "github.com/gin-gonic/gin"
  6. "net/http"
  7. "strconv"
  8. )
  9. func (cb ControllerBase) RunningLogHandler(c *gin.Context) {
  10. var err error
  11. defer func() {
  12. // 统一的异常处理
  13. cb.ErrorProcess(c, "RunningLogHandler", err)
  14. }()
  15. // 从缓存中拿到日志信息,拼接后返回
  16. strLastFewTimes := c.DefaultQuery("the_last_few_times", "3")
  17. lastFewTimes, err := strconv.Atoi(strLastFewTimes)
  18. if err != nil {
  19. return
  20. }
  21. tmpOnceLogs := log_helper.GetRecentOnceLogs(lastFewTimes)
  22. replyOnceLog := backend.NewReplyRunningLog()
  23. replyOnceLog.RecentLogs = append(replyOnceLog.RecentLogs, tmpOnceLogs...)
  24. c.JSON(http.StatusOK, replyOnceLog)
  25. }