Skip to content

Commit ffcf6ba

Browse files
authored
Merge pull request #8 from octo/context
fix: Make `contextAttemptKey` its own type.
2 parents 626d767 + 6a772f7 commit ffcf6ba

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

retry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ func Abort(err error) Error {
118118
return permanentError{err}
119119
}
120120

121-
var contextAttemptKey struct{}
121+
type ctxKey struct{}
122122

123123
func withAttempt(ctx context.Context, attempt int) context.Context {
124-
return context.WithValue(ctx, contextAttemptKey, attempt)
124+
return context.WithValue(ctx, ctxKey{}, attempt)
125125
}
126126

127127
// Attempt returns the number of previous attempts. In other words, it returns
128128
// the zero-based index of the request.
129129
//
130130
// Only call this function from within a retried function.
131131
func Attempt(ctx context.Context) int {
132-
i := ctx.Value(contextAttemptKey)
132+
i := ctx.Value(ctxKey{})
133133
if i == nil {
134134
return 0
135135
}

0 commit comments

Comments
 (0)