-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add a component to support rate limt control #29
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v-0.0.1 singleton demo
not:
but:
example: Fixes #20 |
not:
but:
example: Fixes #20 |
not:
but:
|
Suggest to rename filename |
} | ||
return func(c *gin.Context) { | ||
if !tb.Allow() { | ||
c.String(503, "Too many request") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use constant in http
or define a constant in OpenKF/server/internal/common/code.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i'll solve it
@AllianceTing Please check CI report https://github.com/OpenIMSDK/OpenKF/actions/runs/5418577637/jobs/9850806240?pr=29 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format coding style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix bug
Signed-off-by: SgitBusity <[email protected]>
transfer to I18N
Signed-off-by: SgitBusity <[email protected]>
Signed-off-by: SgitBusity <[email protected]>
fix return formating Signed-off-by: SgitBusity <[email protected]>
|
||
// allow frequency | ||
func (tb *frequencyControlByTokenBucket) Allow() bool { | ||
tb.mtx.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such as sync.RWMutex
|
||
// define rate limit struct | ||
type frequencyControlByTokenBucket struct { | ||
refreshRate float64 // 令牌的刷新速率 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use English
mtx sync.Mutex // 互斥锁 | ||
} | ||
|
||
// allow frequency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func comment, capitalized
} | ||
return func(c *gin.Context) { | ||
if !tb.Allow() { | ||
c.String(503, "Too many request") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return: gin.Context the mechanism of error processing
} | ||
|
||
// registried a middle ware | ||
func LimitHandler(maxConn int, refreshRate float64) gin.HandlerFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write unit testing
// define rate limit struct | ||
type frequencyControlByTokenBucket struct { | ||
refreshRate float64 // 令牌的刷新速率 | ||
capacity int64 // 桶的容量 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int?
👀 What this PR does / why we need it:
🅰 Which issue(s) this PR fixes:
Fixes #20
📝 Special notes for your reviewer:
🎯 Describe how to verify it
📑 Additional documentation e.g., RFC, notion, Google docs, usage docs, etc.: