Skip to content

Commit ffdf59d

Browse files
authored
Enable gofumpt linter; format code gofumpt -w . (#1576)
1 parent b79233f commit ffdf59d

20 files changed

Lines changed: 35 additions & 49 deletions

.github/workflows/lint.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ jobs:
1313
with:
1414
go-version: 1.20.x
1515
- run: go version
16-
- run: diff -u <(echo -n) <(gofmt -d .)
1716
- name: Run golangci-lint
1817
uses: golangci/golangci-lint-action@v3
1918
with:
2019
version: v1.51.1
21-
args: --enable=nolintlint,gochecknoinits,bodyclose --verbose
20+
args: --enable=nolintlint,gochecknoinits,bodyclose,gofumpt --verbose

args_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestArgsEscape(t *testing.T) {
182182

183183
// Test all characters
184184
k := "f.o,1:2/4"
185-
var v = make([]byte, 256)
185+
v := make([]byte, 256)
186186
for i := 0; i < 256; i++ {
187187
v[i] = byte(i)
188188
}
@@ -210,7 +210,7 @@ func TestPathEscape(t *testing.T) {
210210
testPathEscape(t, "*") // See https://github.com/golang/go/issues/11202
211211

212212
// Test all characters
213-
var pathSegment = make([]byte, 256)
213+
pathSegment := make([]byte, 256)
214214
for i := 0; i < 256; i++ {
215215
pathSegment[i] = byte(i)
216216
}

bytesconv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func ParseUfloat(buf []byte) (float64, error) {
204204
}
205205
b := buf
206206
var v uint64
207-
var offset = 1.0
207+
offset := 1.0
208208
var pointFound bool
209209
for i, c := range b {
210210
if c < '0' || c > '9' {

bytesconv_table_gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090
// meaning to individual path segments. This package
9191
// only manipulates the path as a whole, so we allow those
9292
// last three as well. That leaves only ? to escape.
93-
var a = quotedArgShouldEscapeTable
93+
a := quotedArgShouldEscapeTable
9494

9595
for _, v := range `$&+,/:;=@` {
9696
a[v] = 0
@@ -106,7 +106,7 @@ func main() {
106106
fmt.Fprintf(w, "const quotedArgShouldEscapeTable = %q\n", quotedArgShouldEscapeTable)
107107
fmt.Fprintf(w, "const quotedPathShouldEscapeTable = %q\n", quotedPathShouldEscapeTable)
108108

109-
if err := os.WriteFile("bytesconv_table.go", w.Bytes(), 0660); err != nil {
109+
if err := os.WriteFile("bytesconv_table.go", w.Bytes(), 0o660); err != nil {
110110
log.Fatal(err)
111111
}
112112
}

client_timing_wait_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func benchmarkClientGetEndToEndWaitConnInmemory(b *testing.B, parallelism int) {
4040
ch := make(chan struct{})
4141
sleepDuration := 50 * time.Millisecond
4242
go func() {
43-
4443
if err := Serve(ln, newFasthttpSleepEchoHandler(sleepDuration)); err != nil {
4544
b.Errorf("error when serving requests: %v", err)
4645
}

cookie.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ func (c *Cookie) ParseBytes(src []byte) error {
411411
}
412412
}
413413
}
414-
415414
} else if len(kv.value) != 0 {
416415
// Case insensitive switch on first char
417416
switch kv.value[0] | 0x20 {

fasthttpproxy/proxy_env.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func FasthttpProxyHTTPDialerTimeout(timeout time.Duration) fasthttp.DialFunc {
4747
authHTTPSStorage := &atomic.Value{}
4848

4949
return func(addr string) (net.Conn, error) {
50-
5150
port, _, err := net.SplitHostPort(addr)
5251
if err != nil {
5352
return nil, fmt.Errorf("unexpected addr format: %w", err)

fasthttputil/pipeconns.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ var (
218218
errConnectionClosed = errors.New("connection closed")
219219
)
220220

221-
type timeoutError struct {
222-
}
221+
type timeoutError struct{}
223222

224223
func (e *timeoutError) Error() string {
225224
return "timeout"
@@ -233,10 +232,8 @@ func (e *timeoutError) Timeout() bool {
233232
return true
234233
}
235234

236-
var (
237-
// ErrTimeout is returned from Read() or Write() on timeout.
238-
ErrTimeout = &timeoutError{}
239-
)
235+
// ErrTimeout is returned from Read() or Write() on timeout.
236+
var ErrTimeout = &timeoutError{}
240237

241238
func (c *pipeConn) Close() error {
242239
return c.pc.Close()

fs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestServeFileSmallNoReadFrom(t *testing.T) {
156156
tempdir := t.TempDir()
157157

158158
if err := os.WriteFile(
159-
path.Join(tempdir, "hello"), []byte(teststr), 0666); err != nil {
159+
path.Join(tempdir, "hello"), []byte(teststr), 0o666); err != nil {
160160
t.Fatal(err)
161161
}
162162

header_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,6 @@ func TestRequestHeaderConnectionClose(t *testing.T) {
15181518
if string(h1.Peek(HeaderConnection)) != "close" {
15191519
t.Fatalf("unexpected connection value: %q. Expecting %q", h.Peek("Connection"), "close")
15201520
}
1521-
15221521
}
15231522

15241523
func TestRequestHeaderSetCookie(t *testing.T) {
@@ -1753,7 +1752,6 @@ func TestResponseHeaderAddTrailerError(t *testing.T) {
17531752
if trailer := string(h.Peek(HeaderTrailer)); trailer != expectedTrailer {
17541753
t.Fatalf("unexpected trailer %q. Expected %q", trailer, expectedTrailer)
17551754
}
1756-
17571755
}
17581756

17591757
func TestRequestHeaderAddTrailerError(t *testing.T) {
@@ -1769,7 +1767,6 @@ func TestRequestHeaderAddTrailerError(t *testing.T) {
17691767
if trailer := string(h.Peek(HeaderTrailer)); trailer != expectedTrailer {
17701768
t.Fatalf("unexpected trailer %q. Expected %q", trailer, expectedTrailer)
17711769
}
1772-
17731770
}
17741771

17751772
func TestResponseHeaderCookie(t *testing.T) {
@@ -2789,7 +2786,8 @@ func testRequestHeaderReadSecuredError(t *testing.T, h *RequestHeader, headers s
27892786
}
27902787

27912788
func testResponseHeaderReadSuccess(t *testing.T, h *ResponseHeader, headers string, expectedStatusCode, expectedContentLength int,
2792-
expectedContentType string) {
2789+
expectedContentType string,
2790+
) {
27932791
r := bytes.NewBufferString(headers)
27942792
br := bufio.NewReader(r)
27952793
err := h.Read(br)
@@ -2800,7 +2798,8 @@ func testResponseHeaderReadSuccess(t *testing.T, h *ResponseHeader, headers stri
28002798
}
28012799

28022800
func testRequestHeaderReadSuccess(t *testing.T, h *RequestHeader, headers string, expectedContentLength int,
2803-
expectedRequestURI, expectedHost, expectedReferer, expectedContentType string, expectedTrailer map[string]string) {
2801+
expectedRequestURI, expectedHost, expectedReferer, expectedContentType string, expectedTrailer map[string]string,
2802+
) {
28042803
r := bytes.NewBufferString(headers)
28052804
br := bufio.NewReader(r)
28062805
err := h.Read(br)
@@ -2832,7 +2831,8 @@ func verifyResponseHeaderConnection(t *testing.T, h *ResponseHeader, expectConne
28322831
}
28332832

28342833
func verifyRequestHeader(t *testing.T, h *RequestHeader, expectedContentLength int,
2835-
expectedRequestURI, expectedHost, expectedReferer, expectedContentType string) {
2834+
expectedRequestURI, expectedHost, expectedReferer, expectedContentType string,
2835+
) {
28362836
if h.ContentLength() != expectedContentLength {
28372837
t.Fatalf("Unexpected Content-Length %d. Expected %d", h.ContentLength(), expectedContentLength)
28382838
}
@@ -2922,6 +2922,7 @@ func TestRequestHeader_PeekAll(t *testing.T) {
29222922
expectRequestHeaderAll(t, h, HeaderHost, [][]byte{})
29232923
expectRequestHeaderAll(t, h, "aaa", [][]byte{})
29242924
}
2925+
29252926
func expectRequestHeaderAll(t *testing.T, h *RequestHeader, key string, expectedValue [][]byte) {
29262927
if len(h.PeekAll(key)) != len(expectedValue) {
29272928
t.Fatalf("Unexpected size for key %q: %d. Expected %d", key, len(h.PeekAll(key)), len(expectedValue))

0 commit comments

Comments
 (0)