Skip to content

Commit

Permalink
Use custom type as context key.
Browse files Browse the repository at this point in the history
  • Loading branch information
pstibrany committed Oct 6, 2023
1 parent 7082799 commit 9d8eea6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ type methodLimiter struct {
protectedMethodInflight atomic.Int64
}

type ctxKey string

const (
ctxMethodName = "method"
ctxMethodName ctxKey = "method"

metaAbortRequest = "abort-request"
)

Expand Down Expand Up @@ -322,8 +325,8 @@ func (m *methodLimiter) RPCCallStarting(ctx context.Context, methodName string,
func (m *methodLimiter) RPCCallFinished(ctx context.Context) {
m.allInflight.Dec()

methodName := ctx.Value(ctxMethodName).(string)
if methodName == m.protectedMethod && m.protectedMethodInflightLimit > 0 {
methodName := ctx.Value(ctxMethodName).(ctxKey)
if string(methodName) == m.protectedMethod && m.protectedMethodInflightLimit > 0 {
m.protectedMethodInflight.Dec()
}
}

0 comments on commit 9d8eea6

Please sign in to comment.