30 lines
646 B
Go
Raw Normal View History

2023-06-04 22:54:54 +08:00
package filter
import (
2024-09-29 14:08:55 +08:00
"mylomen_server/common/constant"
"mylomen_server/service"
2023-06-04 22:54:54 +08:00
"net/http"
"github.com/labstack/echo/v4"
)
// UseLimit limit
func UseLimit(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
corpId := c.Get(constant.CorpId).(uint64)
bizId := c.Get(constant.BizId).(uint64)
uid := c.Get(constant.UID).(uint64)
2024-09-29 21:12:57 +08:00
breakLimit := service.ApiLimit.BreakLimit(c.Request().Context(), corpId, bizId, uid)
2023-06-04 22:54:54 +08:00
if breakLimit {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": http.StatusNotAcceptable,
"msg": "breaking the interface limit",
})
}
return next(c)
}
}