Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+29 -14
View File
@@ -40,7 +40,9 @@ func TestClientKey(t *testing.T) {
{"", ""},
}
for _, tc := range tests {
req := &http.Request{RemoteAddr: tc.remote}
req := &http.Request{
RemoteAddr: tc.remote,
}
if got := clientKey(req); got != tc.want {
t.Errorf("clientKey(%q) = %q, want %q", tc.remote, got, tc.want)
}
@@ -49,7 +51,9 @@ func TestClientKey(t *testing.T) {
func TestStatusRecorder(t *testing.T) {
t.Run("first WriteHeader wins", func(t *testing.T) {
rec := &statusRecorder{ResponseWriter: httptest.NewRecorder()}
rec := &statusRecorder{
ResponseWriter: httptest.NewRecorder(),
}
rec.WriteHeader(http.StatusTeapot)
rec.WriteHeader(http.StatusInternalServerError)
if rec.status != http.StatusTeapot {
@@ -58,7 +62,9 @@ func TestStatusRecorder(t *testing.T) {
})
t.Run("Write implies 200 and counts bytes", func(t *testing.T) {
inner := httptest.NewRecorder()
rec := &statusRecorder{ResponseWriter: inner}
rec := &statusRecorder{
ResponseWriter: inner,
}
rec.Write([]byte("hello"))
rec.Write([]byte(" world"))
if rec.status != http.StatusOK || rec.bytes != 11 {
@@ -81,9 +87,10 @@ func TestAccessLog(t *testing.T) {
want string // regexp for the whole line
}{
{
name: "no body defaults to 200 and -",
handler: func(http.ResponseWriter, *http.Request) {},
want: `^192\.0\.2\.1 - - ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 -$`,
name: "no body defaults to 200 and -",
handler: func(http.ResponseWriter, *http.Request) {
},
want: `^192\.0\.2\.1 - - ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 -$`,
},
{
name: "status and size",
@@ -94,15 +101,20 @@ func TestAccessLog(t *testing.T) {
want: `^192\.0\.2\.1 - - ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 404 4$`,
},
{
name: "basic auth user is escaped",
handler: func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("x")) },
setup: func(r *http.Request) { r.SetBasicAuth(`bo"b`, "pw") },
want: `^192\.0\.2\.1 - bo\\x22b ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 1$`,
name: "basic auth user is escaped",
handler: func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("x"))
},
setup: func(r *http.Request) {
r.SetBasicAuth(`bo"b`, "pw")
},
want: `^192\.0\.2\.1 - bo\\x22b ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 1$`,
},
{
name: "combined adds referer and user agent",
combined: true,
handler: func(http.ResponseWriter, *http.Request) {},
handler: func(http.ResponseWriter, *http.Request) {
},
setup: func(r *http.Request) {
r.Header.Set("Referer", "http://ref/")
r.Header.Set("User-Agent", `ua "1"`)
@@ -112,9 +124,12 @@ func TestAccessLog(t *testing.T) {
{
name: "combined with missing headers",
combined: true,
handler: func(http.ResponseWriter, *http.Request) {},
setup: func(r *http.Request) { r.Header.Del("User-Agent") },
want: `^192\.0\.2\.1 - - ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 - "-" "-"$`,
handler: func(http.ResponseWriter, *http.Request) {
},
setup: func(r *http.Request) {
r.Header.Del("User-Agent")
},
want: `^192\.0\.2\.1 - - ` + clfTime + ` "GET /path\?q=1 HTTP/1\.1" 200 - "-" "-"$`,
},
}
for _, tc := range tests {