shaoyongjun 43d28c5500 to:sync
2024-09-29 21:12:57 +08:00

30 lines
646 B
Go

package filter
import (
"mylomen_server/common/constant"
"mylomen_server/service"
"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)
breakLimit := service.ApiLimit.BreakLimit(c.Request().Context(), corpId, bizId, uid)
if breakLimit {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": http.StatusNotAcceptable,
"msg": "breaking the interface limit",
})
}
return next(c)
}
}