初始化项目
This commit is contained in:
39
controller/rate_limit_controller.go
Normal file
39
controller/rate_limit_controller.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
var (
|
||||
RateLimit = rateLimit{}
|
||||
)
|
||||
|
||||
type rateLimit struct{}
|
||||
|
||||
// SetTenantRateLimit 设置租户限流配置
|
||||
func (c *rateLimit) SetTenantRateLimit(ctx context.Context, req *dto.SetTenantRateLimitReq) (res *dto.SetTenantRateLimitRes, err error) {
|
||||
// 注意:实际使用的是config.yml中的全局配置,此接口仅用于兼容旧API
|
||||
// 实际限流参数请修改config.yml中的tenantRateLimit部分
|
||||
|
||||
return &dto.SetTenantRateLimitRes{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetTenantRateLimitUsage 获取租户限流使用情况
|
||||
func (c *rateLimit) GetTenantRateLimitUsage(ctx context.Context, req *dto.GetTenantRateLimitUsageReq) (res *dto.GetTenantRateLimitUsageRes, err error) {
|
||||
current, max, err := service.RateLimit.GetTenantCurrentUsage(ctx, req.TenantID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetTenantRateLimitUsageRes{
|
||||
TenantID: req.TenantID,
|
||||
CurrentUsed: current,
|
||||
MaxAllowed: max,
|
||||
UsagePercent: float64(current) / float64(max) * 100,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user