controller_base.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package v1
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/backend/controllers/base"
  4. "github.com/allanpk716/ChineseSubFinder/internal/logic/cron_helper"
  5. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  6. "github.com/gin-gonic/gin"
  7. "github.com/sirupsen/logrus"
  8. "net/http"
  9. )
  10. type ControllerBase struct {
  11. log *logrus.Logger
  12. cronHelper *cron_helper.CronHelper
  13. StaticFileSystemBackEnd *base.StaticFileSystemBackEnd
  14. }
  15. func NewControllerBase(log *logrus.Logger, cronHelper *cron_helper.CronHelper) *ControllerBase {
  16. return &ControllerBase{
  17. log: log,
  18. cronHelper: cronHelper,
  19. StaticFileSystemBackEnd: base.NewStaticFileSystemBackEnd(log),
  20. }
  21. }
  22. func (cb ControllerBase) GetVersion() string {
  23. return "v1"
  24. }
  25. func (cb *ControllerBase) ErrorProcess(c *gin.Context, funcName string, err error) {
  26. if err != nil {
  27. cb.log.Errorln(funcName, err.Error())
  28. c.JSON(http.StatusInternalServerError, backend.ReplyCommon{Message: err.Error()})
  29. }
  30. }