Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xzxt-api-report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
雷紫添
xzxt-api-report
Commits
e30aa59f
Commit
e30aa59f
authored
Dec 23, 2020
by
雷紫添
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加限流空置。
parent
07e51ac9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
src/main/java/com/founder/common/IpADdress.java
+10
-0
src/main/java/com/founder/ratelimit/guava/controller/TestController.java
+10
-0
No files found.
src/main/java/com/founder/common/IpADdress.java
View file @
e30aa59f
package
com
.
founder
.
common
;
package
com
.
founder
.
common
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
public
class
IpADdress
{
public
class
IpADdress
{
public
String
name
;
public
String
name
;
public
String
code
;
public
String
code
;
...
@@ -19,4 +25,8 @@ public class IpADdress {
...
@@ -19,4 +25,8 @@ public class IpADdress {
public
void
setCode
(
String
code
)
{
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
static
HttpServletRequest
getRequest
()
{
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
return
(
requestAttributes
==
null
)
?
null
:
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
}
}
}
src/main/java/com/founder/ratelimit/guava/controller/TestController.java
View file @
e30aa59f
...
@@ -2,11 +2,15 @@ package com.founder.ratelimit.guava.controller;
...
@@ -2,11 +2,15 @@ package com.founder.ratelimit.guava.controller;
import
cn.hutool.core.lang.Dict
;
import
cn.hutool.core.lang.Dict
;
import
com.founder.common.IpADdress
;
import
com.founder.ratelimit.guava.annotation.RateLimiter
;
import
com.founder.ratelimit.guava.annotation.RateLimiter
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
* <p>
* <p>
* 测试
* 测试
...
@@ -22,9 +26,15 @@ public class TestController {
...
@@ -22,9 +26,15 @@ public class TestController {
@RateLimiter
(
value
=
0.1
)
@RateLimiter
(
value
=
0.1
)
@GetMapping
(
"/test1"
)
@GetMapping
(
"/test1"
)
public
Dict
test1
()
{
public
Dict
test1
()
{
HttpServletRequest
request
=
IpADdress
.
getRequest
();
String
key
=
request
.
getHeader
(
"founder.authorization"
);
if
(
""
.
equals
(
key
)||
key
==
null
){
return
Dict
.
create
().
set
(
"msg"
,
"无权限"
);
}
else
{
log
.
info
(
"【test1】被执行了。。。。。"
);
log
.
info
(
"【test1】被执行了。。。。。"
);
return
Dict
.
create
().
set
(
"msg"
,
"hello,world!"
).
set
(
"description"
,
"别想一直看到我,不信你快速刷新看看~"
);
return
Dict
.
create
().
set
(
"msg"
,
"hello,world!"
).
set
(
"description"
,
"别想一直看到我,不信你快速刷新看看~"
);
}
}
}
@GetMapping
(
"/test2"
)
@GetMapping
(
"/test2"
)
public
Dict
test2
()
{
public
Dict
test2
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment