Skip to content

Commit d3397c6

Browse files
authored
Enable wastedassign, whitespace linters; fix issues (#1665)
1 parent 8ecfc98 commit d3397c6

7 files changed

+7
-15
lines changed

.golangci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ linters:
4545
- unparam
4646
- usestdlibvars
4747
- varnamelen
48-
- wastedassign
49-
- whitespace
5048
- wrapcheck
5149
- wsl
5250

args.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func decodeArgAppend(dst, src []byte) []byte {
551551
return append(dst, src...)
552552
}
553553

554-
idx := 0
554+
var idx int
555555
switch {
556556
case idxPercent == -1:
557557
idx = idxPlus

server.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -1780,8 +1780,6 @@ const DefaultConcurrency = 256 * 1024
17801780
func (s *Server) Serve(ln net.Listener) error {
17811781
var lastOverflowErrorTime time.Time
17821782
var lastPerIPErrorTime time.Time
1783-
var c net.Conn
1784-
var err error
17851783

17861784
maxWorkersCount := s.getConcurrency()
17871785

@@ -1813,7 +1811,8 @@ func (s *Server) Serve(ln net.Listener) error {
18131811
defer atomic.AddInt32(&s.open, -1)
18141812

18151813
for {
1816-
if c, err = acceptConn(s, ln, &lastPerIPErrorTime); err != nil {
1814+
c, err := acceptConn(s, ln, &lastPerIPErrorTime)
1815+
if err != nil {
18171816
wp.Stop()
18181817
if err == io.EOF {
18191818
return nil
@@ -1846,7 +1845,6 @@ func (s *Server) Serve(ln net.Listener) error {
18461845
time.Sleep(s.SleepWhenConcurrencyLimitsExceeded)
18471846
}
18481847
}
1849-
c = nil
18501848
}
18511849
}
18521850

@@ -2292,7 +2290,6 @@ func (s *Server) serveConn(c net.Conn) (err error) {
22922290
// 'Expect: 100-continue' request handling.
22932291
// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 for details.
22942292
if ctx.Request.MayContinue() {
2295-
22962293
// Allow the ability to deny reading the incoming request body
22972294
if s.ContinueHandler != nil {
22982295
if continueReadingRequest = s.ContinueHandler(&ctx.Request.Header); !continueReadingRequest {
@@ -2582,7 +2579,7 @@ func acquireByteReader(ctxP **RequestCtx) (*bufio.Reader, error) {
25822579
c := ctx.c
25832580
s.releaseCtx(ctx)
25842581

2585-
// Make GC happy, so it could garbage collect ctx while we wait for the
2582+
//nolint:wastedassign // Make GC happy, so it could garbage collect ctx while we wait for the
25862583
// next request.
25872584
ctx = nil
25882585
*ctxP = nil

server_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@ func TestServerContinueHandler(t *testing.T) {
19201920
// Expect 100 continue denied
19211921
rw := &readWriter{}
19221922
for i := 0; i < 25; i++ {
1923-
19241923
// Regular requests without Expect 100 continue header
19251924
rw.r.Reset()
19261925
rw.r.WriteString("POST /foo HTTP/1.1\r\nHost: gle.com\r\nContent-Length: 5\r\nContent-Type: a/b\r\n\r\n12345")

streaming_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ aaaaaaaaaa`
3131
s := &Server{
3232
StreamRequestBody: true,
3333
Handler: func(ctx *RequestCtx) {
34-
body := ""
34+
var body string
3535
expected := "aaaaaaaaaa"
3636
if string(ctx.Path()) == "/one" {
3737
body = string(ctx.PostBody())

tcpdialer.go

-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ func (d *TCPDialer) tcpAddrsClean() {
375375
}
376376
return true
377377
})
378-
379378
}
380379
}
381380

workerpool.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ func (wp *workerPool) clean(scratch *[]*workerChan) {
110110
n := len(ready)
111111

112112
// Use binary-search algorithm to find out the index of the least recently worker which can be cleaned up.
113-
l, r, mid := 0, n-1, 0
113+
l, r := 0, n-1
114114
for l <= r {
115-
mid = (l + r) / 2
115+
mid := (l + r) / 2
116116
if criticalTime.After(wp.ready[mid].lastUseTime) {
117117
l = mid + 1
118118
} else {
@@ -238,7 +238,6 @@ func (wp *workerPool) workerFunc(ch *workerChan) {
238238
_ = c.Close()
239239
wp.connState(c, StateClosed)
240240
}
241-
c = nil
242241

243242
if !wp.release(ch) {
244243
break

0 commit comments

Comments
 (0)