Skip to content

Commit

Permalink
Parametrize HasRateLimitStrategy by key (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell authored Jun 7, 2022
1 parent e56d14f commit 6748e16
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions servant-rate-limit/src/Servant/RateLimit/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Servant.Server.Internal.DelayedIO

-- | A class of types which are type-level descriptions of rate-limiting
-- strategies.
class HasRateLimitStrategy (ctx :: [Type]) strategy where
class HasRateLimitStrategy (ctx :: [Type]) strategy key where
-- | `strategyValue` @context backend getKey@ is a function which, given a
-- @backend@ and a function @getKey@ used to compute the key using which
-- the client should be identified, returns a rate-limiting `Strategy`.
Expand All @@ -50,7 +50,7 @@ class HasRateLimitStrategy (ctx :: [Type]) strategy where

instance
(KnownDuration dur, KnownNat capacity, Units.TimeUnit (DurationUnit dur))
=> HasRateLimitStrategy ctx (FixedWindow dur capacity)
=> HasRateLimitStrategy ctx (FixedWindow dur capacity) key
where

strategyValue _ backend getKey = fixedWindow
Expand All @@ -61,7 +61,7 @@ instance

instance
(KnownDuration dur, KnownNat capacity, Units.TimeUnit (DurationUnit dur))
=> HasRateLimitStrategy ctx (SlidingWindow dur capacity)
=> HasRateLimitStrategy ctx (SlidingWindow dur capacity) key
where

strategyValue _ backend getKey = slidingWindow
Expand Down Expand Up @@ -94,7 +94,7 @@ instance KnownSymbol prefix => HasRateLimitPolicy ctx (IPAddressPolicy prefix) w
instance
( HasServer api ctx
, HasContextEntry ctx (Backend key)
, HasRateLimitStrategy ctx strategy
, HasRateLimitStrategy ctx strategy key
, HasRateLimitPolicy ctx policy
, key ~ RateLimitPolicyKey ctx policy
) => HasServer (RateLimit strategy policy :> api) ctx
Expand Down

0 comments on commit 6748e16

Please sign in to comment.