Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
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
Vũ Hoàng Anh
canifa_note
Commits
ab2c8664
Commit
ab2c8664
authored
Oct 09, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: move rate limiter to apiv1
parent
1489feb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
17 deletions
+19
-17
v1.go
api/v1/v1.go
+19
-0
server.go
server/server.go
+0
-17
No files found.
api/v1/v1.go
View file @
ab2c8664
package
v1
import
(
"net/http"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/usememos/memos/api/resource"
"github.com/usememos/memos/plugin/telegram"
...
...
@@ -45,6 +49,21 @@ func (s *APIV1Service) Register(rootGroup *echo.Group) {
// Register API v1 routes.
apiV1Group
:=
rootGroup
.
Group
(
"/api/v1"
)
apiV1Group
.
Use
(
middleware
.
RateLimiterWithConfig
(
middleware
.
RateLimiterConfig
{
Store
:
middleware
.
NewRateLimiterMemoryStoreWithConfig
(
middleware
.
RateLimiterMemoryStoreConfig
{
Rate
:
30
,
Burst
:
100
,
ExpiresIn
:
3
*
time
.
Minute
},
),
IdentifierExtractor
:
func
(
ctx
echo
.
Context
)
(
string
,
error
)
{
id
:=
ctx
.
RealIP
()
return
id
,
nil
},
ErrorHandler
:
func
(
context
echo
.
Context
,
err
error
)
error
{
return
context
.
JSON
(
http
.
StatusForbidden
,
nil
)
},
DenyHandler
:
func
(
context
echo
.
Context
,
identifier
string
,
err
error
)
error
{
return
context
.
JSON
(
http
.
StatusTooManyRequests
,
nil
)
},
}))
apiV1Group
.
Use
(
func
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
JWTMiddleware
(
s
,
next
,
s
.
Secret
)
})
...
...
server/server.go
View file @
ab2c8664
...
...
@@ -77,23 +77,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
Timeout
:
30
*
time
.
Second
,
}))
e
.
Use
(
middleware
.
RateLimiterWithConfig
(
middleware
.
RateLimiterConfig
{
Skipper
:
grpcRequestSkipper
,
Store
:
middleware
.
NewRateLimiterMemoryStoreWithConfig
(
middleware
.
RateLimiterMemoryStoreConfig
{
Rate
:
30
,
Burst
:
100
,
ExpiresIn
:
3
*
time
.
Minute
},
),
IdentifierExtractor
:
func
(
ctx
echo
.
Context
)
(
string
,
error
)
{
id
:=
ctx
.
RealIP
()
return
id
,
nil
},
ErrorHandler
:
func
(
context
echo
.
Context
,
err
error
)
error
{
return
context
.
JSON
(
http
.
StatusForbidden
,
nil
)
},
DenyHandler
:
func
(
context
echo
.
Context
,
identifier
string
,
err
error
)
error
{
return
context
.
JSON
(
http
.
StatusTooManyRequests
,
nil
)
},
}))
serverID
,
err
:=
s
.
getSystemServerID
(
ctx
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to retrieve system server ID"
)
...
...
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