2026-04-11 17:03:22 +08:00
|
|
|
|
package com.lesingle.common.annotation;
|
2026-04-09 12:52:39 +08:00
|
|
|
|
|
|
|
|
|
|
import java.lang.annotation.*;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 接口速率限制注解
|
|
|
|
|
|
* 用于公开接口防止恶意调用
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Target(ElementType.METHOD)
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
|
@Documented
|
|
|
|
|
|
public @interface RateLimit {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 时间窗口内允许的最大请求次数
|
|
|
|
|
|
*/
|
|
|
|
|
|
int permits() default 10;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 时间窗口大小
|
|
|
|
|
|
*/
|
|
|
|
|
|
long duration() default 1;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 时间单位
|
|
|
|
|
|
*/
|
|
|
|
|
|
TimeUnit timeUnit() default TimeUnit.SECONDS;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 限制维度:ip / user
|
|
|
|
|
|
*/
|
|
|
|
|
|
String key() default "ip";
|
|
|
|
|
|
}
|