Skip to content

Commit 1c52337

Browse files
committed
2 parents 24a9e4e + 26d5985 commit 1c52337

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ratelimiter
22

3+
A distributed rate limiter library for Go applications.
4+
35
Currently supports Redis and SQL (GORM) storage backends.
46

57
## Usage Examples

sqlrl/sql.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
type RateLimiter struct {
3030
db *gorm.DB
3131
tableName string
32-
rawQuery string
32+
selectQuery string
3333
insertQuery string
3434
updateQuery string
3535
}
@@ -63,7 +63,7 @@ func New(db *gorm.DB, tableName string) (*RateLimiter, error) {
6363
return nil, errors.Errorf("unsupported dialect %q, must be mysql or postgres", db.Dialector.Name())
6464
}
6565

66-
s.rawQuery = fmt.Sprintf(`
66+
s.selectQuery = fmt.Sprintf(`
6767
WITH kv_select AS (
6868
SELECT %s, %s FROM %s WHERE %s = ? FOR UPDATE
6969
)
@@ -193,7 +193,7 @@ func (s *RateLimiter) attempt(ctx context.Context, req *ratelimiter.ReserveReque
193193
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
194194
var kv kvWrapper
195195

196-
if err := tx.Raw(s.rawQuery, req.Key, req.Key).Scan(&kv).Error; err != nil {
196+
if err := tx.Raw(s.selectQuery, req.Key, req.Key).Scan(&kv).Error; err != nil {
197197
return errors.Wrap(err, "failed to get kv")
198198
}
199199

0 commit comments

Comments
 (0)