001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.components.limiter;
017
018import io.jboot.app.config.annotation.ConfigModel;
019
020/**
021 * 限流的规则 (rule 的值):
022 * 对于Controller的限流:/user/xxx/*:cc:50,/user/xxx/*:tb:50
023 * 对于Service方法的限流:
024 * 1)*.*(*): 所有包下的所有方法的所有参数类型
025 * 2)com.xxx.*.aaa*(int,User): com.xxx包下的所有aaa开头的方法,参数类型为(int,User)
026 */
027@ConfigModel(prefix = "jboot.limit")
028public class LimitConfig {
029
030    /**
031     * 是否开启限流配置,这个的开启或关闭对注解的限流配置不影响
032     */
033    private boolean enable = false;
034
035    /**
036     * 限流规则,多个规则用英文逗号隔开
037     */
038    private String rule;
039
040
041    /**
042     * IP 白名单,不受限流的配置
043     */
044    private String ipWhitelist;
045
046    /**
047     * 默认的降级处理器(被限流后的处理器)
048     */
049    private String fallbackProcesser;
050
051    /**
052     * 被限流后,默认的http code
053     */
054    private int defaultHttpCode = 200;
055
056    /**
057     * 被限流后,当ajax请求的时候,返回默认的json传
058     */
059    private String defaultAjaxContent;
060
061    /**
062     * 被限流后,当http请求的时候,默认渲染的html文件
063     */
064    private String defaultHtmlView;
065
066    public boolean isEnable() {
067        return enable;
068    }
069
070    public void setEnable(boolean enable) {
071        this.enable = enable;
072    }
073
074    public String getRule() {
075        return rule;
076    }
077
078    public void setRule(String rule) {
079        this.rule = rule;
080    }
081
082    public String getIpWhitelist() {
083        return ipWhitelist;
084    }
085
086    public void setIpWhitelist(String ipWhitelist) {
087        this.ipWhitelist = ipWhitelist;
088    }
089
090    public String getFallbackProcesser() {
091        return fallbackProcesser;
092    }
093
094    public void setFallbackProcesser(String fallbackProcesser) {
095        this.fallbackProcesser = fallbackProcesser;
096    }
097
098    public int getDefaultHttpCode() {
099        return defaultHttpCode;
100    }
101
102    public void setDefaultHttpCode(int defaultHttpCode) {
103        this.defaultHttpCode = defaultHttpCode;
104    }
105
106    public String getDefaultAjaxContent() {
107        return defaultAjaxContent;
108    }
109
110    public void setDefaultAjaxContent(String defaultAjaxContent) {
111        this.defaultAjaxContent = defaultAjaxContent;
112    }
113
114    public String getDefaultHtmlView() {
115        return defaultHtmlView;
116    }
117
118    public void setDefaultHtmlView(String defaultHtmlView) {
119        this.defaultHtmlView = defaultHtmlView;
120    }
121}