35 lines
636 B
Java
35 lines
636 B
Java
|
|
package com.competition.common.annotation;
|
|||
|
|
|
|||
|
|
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";
|
|||
|
|
}
|