-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #59 Signed-off-by: Michael Gasch <mgasch@vmware.com>
- Loading branch information
Michael Gasch
committed
Oct 11, 2021
1 parent
74757a6
commit 60db3c3
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2021 The CloudEvents Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package http | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
type RateLimiter interface { | ||
// Take attempts to take one token from the rate limiter for the specified | ||
// request. It returns ok when this operation was successful. In case ok is | ||
// false, reset will indicate the time in seconds when it is safe to perform | ||
// another attempt. An error is returned when this operation failed, e.g. due to | ||
// a backend error. | ||
Take(ctx context.Context, r *http.Request) (ok bool, reset uint64, err error) | ||
// Close terminates rate limiter and cleans up any data structures or | ||
// connections that may remain open. After a store is stopped, Take() should | ||
// always return zero values. | ||
Close(ctx context.Context) error | ||
} | ||
|
||
type noOpLimiter struct{} | ||
|
||
func (n noOpLimiter) Take(ctx context.Context, r *http.Request) (bool, uint64, error) { | ||
return true, 0, nil | ||
} | ||
|
||
func (n noOpLimiter) Close(ctx context.Context) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters