From c048db76e6fe2a37b7360e070beffc5f0bbeeeee Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 22 Jun 2021 21:14:38 +0200 Subject: [PATCH] fix: ineffectual assignments --- handler_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/handler_test.go b/handler_test.go index fe3327e..6dcd13c 100644 --- a/handler_test.go +++ b/handler_test.go @@ -51,13 +51,11 @@ func TestWith(t *testing.T) { middleware := func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - newr := r - // first time -> store 1 value := r.Context().Value(key) if value == nil { - newr = r.WithContext(context.WithValue(r.Context(), key, int(1))) - next.ServeHTTP(w, newr) + r = r.WithContext(context.WithValue(r.Context(), key, int(1))) + next.ServeHTTP(w, r) return } @@ -67,8 +65,8 @@ func TestWith(t *testing.T) { t.Fatalf("value is not an int") } cast++ - newr = r.WithContext(context.WithValue(r.Context(), key, cast)) - next.ServeHTTP(w, newr) + r = r.WithContext(context.WithValue(r.Context(), key, cast)) + next.ServeHTTP(w, r) }) }