running_log.go 772 B

123456789101112131415161718192021222324252627282930
  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. )
  8. func (cb ControllerBase) RunningLogHandler(c *gin.Context) {
  9. var err error
  10. defer func() {
  11. // 统一的异常处理
  12. cb.ErrorProcess(c, "RunningLogHandler", err)
  13. }()
  14. reqRunningLog := backend.ReqRunningLog{}
  15. err = c.ShouldBindJSON(&reqRunningLog)
  16. if err != nil {
  17. return
  18. }
  19. // 从缓存中拿到日志信息,拼接后返回
  20. tmpOnceLogs := log_helper.GetRecentOnceLogs(reqRunningLog.TheLastFewTimes)
  21. replyOnceLog := backend.NewReplyRunningLog()
  22. replyOnceLog.RecentLogs = append(replyOnceLog.RecentLogs, tmpOnceLogs...)
  23. c.JSON(http.StatusOK, replyOnceLog)
  24. }