Skip to content

Commit

Permalink
Check meter
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Dec 5, 2023
1 parent cde7d39 commit a165d5b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion meters/meters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ func WithMeter(apiMeter MeterProvider, meterName string, meterValue float64, dim
ctx := r.Context()
ctxMeter := apiMeter.NewMeter(authn.ForContext(ctx))
r = r.WithContext(context.WithValue(ctx, meterCtxKey, ctxMeter))
if err := ctxMeter.Meter(meterName, meterValue, dims); err != nil {
http.Error(w, "429", http.StatusTooManyRequests)
return
}
next.ServeHTTP(w, r)
ctxMeter.Meter(meterName, meterValue, dims)
})
}
}
Expand Down

0 comments on commit a165d5b

Please sign in to comment.