Skip to content

Commit

Permalink
Set RateLimit cost with Compute Units
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon committed Jul 10, 2024
1 parent 6f3d384 commit 3d5126c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion middleware/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/0xsequence/quotacontrol/proto"
"github.com/go-chi/httprate"
"github.com/lestrrat-go/jwx/v2/jwt"
)

Expand Down Expand Up @@ -205,8 +206,9 @@ func getProjectID(ctx context.Context) (uint64, bool) {
return v, ok
}

// WithComputeUnits sets the compute units to the context.
// WithComputeUnits sets the compute units and rate limit increment to the context.
func WithComputeUnits(ctx context.Context, cu int64) context.Context {
ctx = httprate.WithIncrement(ctx, int(cu))
return context.WithValue(ctx, ctxKeyComputeUnits, cu)
}

Expand Down

0 comments on commit 3d5126c

Please sign in to comment.