Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
t0r
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
t0r
Commits
fe97baec
"wp-content/git@git.autistici.org:ai/noblogs-wp.git" did not exist on "9cb4573da23472ec93de672b292ccbf0af6dd17d"
Commit
fe97baec
authored
12 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
fix setting memcache counters for the first time
parent
3ea4d874
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dos.go
+3
-2
3 additions, 2 deletions
dos.go
with
3 additions
and
2 deletions
dos.go
+
3
−
2
View file @
fe97baec
...
@@ -13,6 +13,7 @@ var (
...
@@ -13,6 +13,7 @@ var (
dosKeyNamespace
=
"dos"
dosKeyNamespace
=
"dos"
memcacheAddr
=
flag
.
String
(
"memcache"
,
"127.0.0.1:11211"
,
"Memcache address"
)
memcacheAddr
=
flag
.
String
(
"memcache"
,
"127.0.0.1:11211"
,
"Memcache address"
)
whitelistedAddrs
=
flag
.
String
(
"whitelist-addrs"
,
"127.0.0.1"
,
"Whitelisted addresses (no rate limiting), comma separated"
)
)
)
type
Limiter
struct
{
type
Limiter
struct
{
...
@@ -31,7 +32,7 @@ func NewLimiter(param string, count int, period int, extractfn func(*http.Reques
...
@@ -31,7 +32,7 @@ func NewLimiter(param string, count int, period int, extractfn func(*http.Reques
Count
:
count
,
Count
:
count
,
Period
:
period
,
Period
:
period
,
extractValue
:
extractfn
,
extractValue
:
extractfn
,
whitelistedValues
:
make
([]
string
,
0
),
whitelistedValues
:
strings
.
Split
(
*
whitelistedAddrs
,
","
),
mc
:
memcache
.
New
(
*
memcacheAddr
),
mc
:
memcache
.
New
(
*
memcacheAddr
),
}
}
}
}
...
@@ -58,7 +59,7 @@ func (l *Limiter) Limit(handler http.Handler) http.Handler {
...
@@ -58,7 +59,7 @@ func (l *Limiter) Limit(handler http.Handler) http.Handler {
result
,
err
:=
l
.
mc
.
Increment
(
key
,
1
)
result
,
err
:=
l
.
mc
.
Increment
(
key
,
1
)
if
err
!=
nil
{
if
err
!=
nil
{
result
=
1
result
=
1
if
err
=
l
.
mc
.
Add
(
&
memcache
.
Item
{
Key
:
key
,
Value
:
[]
byte
{
0
,
0
,
0
,
0
}
,
Expiration
:
int32
(
l
.
Period
)});
err
!=
nil
{
if
err
=
l
.
mc
.
Add
(
&
memcache
.
Item
{
Key
:
key
,
Value
:
[]
byte
(
"1"
)
,
Expiration
:
int32
(
l
.
Period
)});
err
!=
nil
{
// Possible race for who adds to the cache first.
// Possible race for who adds to the cache first.
if
result
,
err
=
l
.
mc
.
Increment
(
key
,
1
);
err
!=
nil
{
if
result
,
err
=
l
.
mc
.
Increment
(
key
,
1
);
err
!=
nil
{
log
.
Printf
(
"Memcache failed for '%s': %s"
,
key
,
err
)
log
.
Printf
(
"Memcache failed for '%s': %s"
,
key
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment