StartRequestTimer starts a new request timer.
(r *http.Request, timeout time.Duration)
| 13 | |
| 14 | // StartRequestTimer starts a new request timer. |
| 15 | func StartRequestTimer(r *http.Request, timeout time.Duration) (*http.Request, context.CancelFunc) { |
| 16 | ctx := r.Context() |
| 17 | ctx = context.WithValue(ctx, timerSinceCtxKey{}, time.Now()) |
| 18 | ctx, cancel := context.WithTimeout(ctx, timeout) //nolint:gosec // cancel is called |
| 19 | return r.WithContext(ctx), cancel |
| 20 | } |
| 21 | |
| 22 | // RequestDuration returns the duration since the timer started in the context. |
| 23 | func RequestDuration(ctx context.Context) time.Duration { |
no outgoing calls