30 lines
643 B
Go
Raw Normal View History

2023-06-04 22:54:54 +08:00
package filter
import (
"ai-gateway/common/constant"
"ai-gateway/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)
2024-02-21 12:04:40 +08:00
breakLimit := service.ThirdApiLimit.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)
}
}