1
0

controller_base.go 638 B

1234567891011121314151617181920212223242526
  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. "github.com/sirupsen/logrus"
  7. "net/http"
  8. )
  9. type ControllerBase struct {
  10. log *logrus.Logger
  11. }
  12. func NewControllerBase(_logger *logrus.Logger) *ControllerBase {
  13. return &ControllerBase{
  14. log: _logger,
  15. }
  16. }
  17. func (cb *ControllerBase) ErrorProcess(c *gin.Context, funcName string, err error) {
  18. if err != nil {
  19. log_helper.GetLogger().Errorln(funcName, err.Error())
  20. c.JSON(http.StatusInternalServerError, backend.ReplyCommon{Message: err.Error()})
  21. }
  22. }