Skip to content

Commit

Permalink
Specify default function length size
Browse files Browse the repository at this point in the history
Enable linter funlen to limit the function length
and the number of the statements.
  • Loading branch information
miry committed Sep 17, 2021
1 parent 1eed55a commit 40d1075
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ linters:
disable-all: true
enable:
- bodyclose
- funlen
- lll
- misspell

linters-settings:
funlen:
lines: 80
statements: 30

lll:
line-length: 100
tab-width: 1
54 changes: 54 additions & 0 deletions testhelper/upstream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package testhelper

import (
"net"
"testing"
)

type Upstream struct {
listener net.Listener
logger testing.TB
Connections chan net.Conn
}

func NewUpstream(t testing.TB, ignoreData bool) *Upstream {
result := &Upstream{}
result.listen()
result.accept(ignoreData)

return result
}

func (u *Upstream) listen() {
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
u.logger.Fatalf("Failed to create TCP server: %v", err)
}
u.listener = listener
}

func (u *Upstream) accept(ignoreData bool) {
u.Connections = make(chan net.Conn)
go func(u *Upstream) {
conn, err := u.listener.Accept()
if err != nil {
u.logger.Fatalf("Unable to accept TCP connection: %v", err)
}
if ignoreData {
buf := make([]byte, 4000)
for err == nil {
_, err = conn.Read(buf)
}
} else {
u.Connections <- conn
}
}(u)
}

func (u *Upstream) Close() {
u.listener.Close()
}

func (u *Upstream) Addr() string {
return u.listener.Addr().String()
}

0 comments on commit 40d1075

Please sign in to comment.