check_cron.go 658 B

123456789101112131415161718192021222324252627282930
  1. package base
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  4. "github.com/gin-gonic/gin"
  5. "github.com/robfig/cron/v3"
  6. "net/http"
  7. )
  8. func (cb ControllerBase) CheckCronHandler(c *gin.Context) {
  9. var err error
  10. defer func() {
  11. // 统一的异常处理
  12. cb.ErrorProcess(c, "CheckCronHandler", err)
  13. }()
  14. checkCron := backend.ReqCheckCron{}
  15. err = c.ShouldBindJSON(&checkCron)
  16. if err != nil {
  17. return
  18. }
  19. _, err2 := cron.ParseStandard(checkCron.ScanInterval)
  20. if err2 != nil {
  21. c.JSON(http.StatusOK, backend.ReplyCommon{Message: err2.Error()})
  22. return
  23. } else {
  24. c.JSON(http.StatusOK, backend.ReplyCommon{Message: "ok"})
  25. }
  26. }