From f87cf04b20d0ee92acff6e6fde55240ec0f2c262 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Sat, 18 Apr 2020 09:02:26 -0700
Subject: [PATCH] Address new linting issues

---
 httpbin/digest/digest_test.go |  5 -----
 httpbin/handlers.go           |  2 +-
 httpbin/handlers_test.go      | 27 +++++++++++++--------------
 httpbin/helpers.go            |  8 ++++----
 httpbin/middleware.go         |  2 +-
 5 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/httpbin/digest/digest_test.go b/httpbin/digest/digest_test.go
index dc25086..97d55ec 100644
--- a/httpbin/digest/digest_test.go
+++ b/httpbin/digest/digest_test.go
@@ -13,11 +13,6 @@ const (
 	exampleUsername = "Mufasa"
 	examplePassword = "Circle Of Life"
 
-	exampleChallenge string = `Digest realm="testrealm@host.com",
-            qop="auth,auth-int",
-            nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
-            opaque="5ccc069c403ebaf9f0171e9517f40e41"`
-
 	exampleAuthorization string = `Digest username="Mufasa",
 			realm="testrealm@host.com",
 			nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index 5828599..8e0d068 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -228,7 +228,7 @@ func (h *HTTPBin) ResponseHeaders(w http.ResponseWriter, r *http.Request) {
 	args := r.URL.Query()
 	for k, vs := range args {
 		for _, v := range vs {
-			w.Header().Add(http.CanonicalHeaderKey(k), v)
+			w.Header().Add(k, v)
 		}
 	}
 	body, _ := json.Marshal(args)
diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index e554695..7873586 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -15,7 +15,6 @@ import (
 	"net/http"
 	"net/http/httptest"
 	"net/url"
-	"os"
 	"reflect"
 	"regexp"
 	"strconv"
@@ -31,7 +30,7 @@ const alphanumLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012
 var app = New(
 	WithMaxBodySize(maxBodySize),
 	WithMaxDuration(maxDuration),
-	WithObserver(StdLogObserver(log.New(os.Stderr, "", 0))),
+	WithObserver(StdLogObserver(log.New(ioutil.Discard, "", 0))),
 )
 
 var handler = app.Handler()
@@ -216,7 +215,7 @@ func TestHEAD(t *testing.T) {
 	assertStatusCode(t, w, 200)
 	assertBodyEquals(t, w, "")
 
-	contentLengthStr := w.HeaderMap.Get("Content-Length")
+	contentLengthStr := w.Header().Get("Content-Length")
 	if contentLengthStr == "" {
 		t.Fatalf("missing Content-Length header in response")
 	}
@@ -772,7 +771,7 @@ func TestResponseHeaders__OK(t *testing.T) {
 	assertContentType(t, w, jsonContentType)
 
 	for k, expectedValues := range headers {
-		values, ok := w.HeaderMap[k]
+		values, ok := w.Header()[k]
 		if !ok {
 			t.Fatalf("expected header %s in response headers", k)
 		}
@@ -1021,7 +1020,7 @@ func TestDeleteCookies(t *testing.T) {
 
 	for _, c := range w.Result().Cookies() {
 		if c.Name == toDelete {
-			if time.Now().Sub(c.Expires) < (24*365-1)*time.Hour {
+			if time.Since(c.Expires) < (24*365-1)*time.Hour {
 				t.Fatalf("expected cookie %s to be deleted; got %#v", toDelete, c)
 			}
 		}
@@ -1248,7 +1247,7 @@ func TestGzip(t *testing.T) {
 	assertHeader(t, w, "Content-Encoding", "gzip")
 	assertStatusCode(t, w, http.StatusOK)
 
-	zippedContentLengthStr := w.HeaderMap.Get("Content-Length")
+	zippedContentLengthStr := w.Header().Get("Content-Length")
 	if zippedContentLengthStr == "" {
 		t.Fatalf("missing Content-Length header in response")
 	}
@@ -1292,7 +1291,7 @@ func TestDeflate(t *testing.T) {
 	assertHeader(t, w, "Content-Encoding", "deflate")
 	assertStatusCode(t, w, http.StatusOK)
 
-	contentLengthHeader := w.HeaderMap.Get("Content-Length")
+	contentLengthHeader := w.Header().Get("Content-Length")
 	if contentLengthHeader == "" {
 		t.Fatalf("missing Content-Length header in response")
 	}
@@ -1415,7 +1414,7 @@ func TestDelay(t *testing.T) {
 			w := httptest.NewRecorder()
 			handler.ServeHTTP(w, r)
 
-			elapsed := time.Now().Sub(start)
+			elapsed := time.Since(start)
 
 			assertStatusCode(t, w, http.StatusOK)
 			assertHeader(t, w, "Content-Type", jsonContentType)
@@ -1515,7 +1514,7 @@ func TestDrip(t *testing.T) {
 			w := httptest.NewRecorder()
 			handler.ServeHTTP(w, r)
 
-			elapsed := time.Now().Sub(start)
+			elapsed := time.Since(start)
 
 			assertHeader(t, w, "Content-Type", "application/octet-stream")
 			assertStatusCode(t, w, test.code)
@@ -1676,7 +1675,7 @@ func TestRange(t *testing.T) {
 		w := httptest.NewRecorder()
 		handler.ServeHTTP(w, r)
 
-		t.Logf("headers = %v", w.HeaderMap)
+		t.Logf("headers = %v", w.Header())
 		assertStatusCode(t, w, http.StatusPartialContent)
 		assertHeader(t, w, "ETag", "range26")
 		assertHeader(t, w, "Content-Length", "5")
@@ -2256,19 +2255,19 @@ func TestBase64(t *testing.T) {
 		},
 		{
 			"/base64/",
-			"No input data",
+			"no input data",
 		},
 		{
 			"/base64/decode/",
-			"No input data",
+			"no input data",
 		},
 		{
 			"/base64/decode/dmFsaWRfYmFzZTY0X2VuY29kZWRfc3RyaW5n/extra",
-			"Invalid URL",
+			"invalid URL",
 		},
 		{
 			"/base64/unknown/dmFsaWRfYmFzZTY0X2VuY29kZWRfc3RyaW5n",
-			"Invalid operation: unknown",
+			"invalid operation: unknown",
 		},
 	}
 
diff --git a/httpbin/helpers.go b/httpbin/helpers.go
index fe62be3..3b27f98 100644
--- a/httpbin/helpers.go
+++ b/httpbin/helpers.go
@@ -262,7 +262,7 @@ func newBase64Helper(path string) (*base64Helper, error) {
 	parts := strings.Split(path, "/")
 
 	if len(parts) != 3 && len(parts) != 4 {
-		return nil, errors.New("Invalid URL")
+		return nil, errors.New("invalid URL")
 	}
 
 	var b base64Helper
@@ -277,15 +277,15 @@ func newBase64Helper(path string) (*base64Helper, error) {
 		// - /base64/encode/input_str
 		b.operation = parts[2]
 		if b.operation != "encode" && b.operation != "decode" {
-			return nil, fmt.Errorf("Invalid operation: %s", b.operation)
+			return nil, fmt.Errorf("invalid operation: %s", b.operation)
 		}
 		b.data = parts[3]
 	}
 	if len(b.data) == 0 {
-		return nil, errors.New("No input data")
+		return nil, errors.New("no input data")
 	}
 	if len(b.data) >= Base64MaxLen {
-		return nil, fmt.Errorf("Input length - %d, Cannot handle input >= %d", len(b.data), Base64MaxLen)
+		return nil, fmt.Errorf("input length - %d, Cannot handle input >= %d", len(b.data), Base64MaxLen)
 	}
 
 	return &b, nil
diff --git a/httpbin/middleware.go b/httpbin/middleware.go
index 6576610..e35a5a9 100644
--- a/httpbin/middleware.go
+++ b/httpbin/middleware.go
@@ -127,7 +127,7 @@ func observe(o Observer, h http.Handler) http.Handler {
 			Method:   r.Method,
 			URI:      r.URL.RequestURI(),
 			Size:     mw.Size(),
-			Duration: time.Now().Sub(t),
+			Duration: time.Since(t),
 		})
 	})
 }
-- 
GitLab