mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
lock and unlock mutex correctly
This commit is contained in:
parent
8bd8edc90d
commit
fcf78afddc
1 changed files with 9 additions and 3 deletions
12
bird/bird.go
12
bird/bird.go
|
@ -10,7 +10,7 @@ import (
|
|||
var ClientConf BirdConfig
|
||||
var StatusConf StatusConfig
|
||||
var RateLimitConf struct {
|
||||
sync.Mutex
|
||||
sync.RWMutex
|
||||
Conf RateLimitConfig
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,17 @@ func InstallRateLimitReset() {
|
|||
}
|
||||
|
||||
func checkRateLimit() bool {
|
||||
if !RateLimitConf.Conf.Enabled {
|
||||
RateLimitConf.RLock()
|
||||
check := !RateLimitConf.Conf.Enabled
|
||||
RateLimitConf.RUnlock()
|
||||
if check {
|
||||
return true
|
||||
}
|
||||
|
||||
if RateLimitConf.Conf.Reqs > RateLimitConf.Conf.Max {
|
||||
RateLimitConf.RLock()
|
||||
check = RateLimitConf.Conf.Reqs > RateLimitConf.Conf.Max
|
||||
RateLimitConf.RUnlock()
|
||||
if check {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue