Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: Fix new complaints from new golangci-lint version #100

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func dialContextWithDNSCache(resolver *dnscache.Resolver, baseDialCtx DialContex

if net.ParseIP(host) != nil {
// For IP only setups there is no need for DNS lookups.
return baseDialCtx(ctx, "tcp", addr)
return baseDialCtx(ctx, network, addr)
}

ips, err := resolver.LookupHost(ctx, host)
Expand All @@ -578,7 +578,7 @@ func dialContextWithDNSCache(resolver *dnscache.Resolver, baseDialCtx DialContex
}

for _, ip := range ips {
conn, err = baseDialCtx(ctx, "tcp", net.JoinHostPort(ip, port))
conn, err = baseDialCtx(ctx, network, net.JoinHostPort(ip, port))
if err == nil {
break
}
Expand Down
24 changes: 12 additions & 12 deletions reverse/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func TestProxyCancellation(t *testing.T) {
const backendResponse = "I am the backend"

reqInFlight := make(chan struct{})
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
close(reqInFlight) // cause the client to cancel its request

select {
Expand Down Expand Up @@ -469,7 +469,7 @@ func req(t *testing.T, v string) *http.Request {

// Issue 12344
func TestNilBody(t *testing.T) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("hi"))
}))
defer backend.Close()
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestNilBody(t *testing.T) {
// Issue 15524
func TestUserAgentHeader(t *testing.T) {
const explicitUA = "explicit UA"
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/noua" {
if c := r.Header.Get("User-Agent"); c != "" {
t.Errorf("handler got non-empty User-Agent header %q", c)
Expand Down Expand Up @@ -695,7 +695,7 @@ func TestProxyErrorHandler(t *testing.T) {
{
name: "errorhandler",
wantCode: http.StatusTeapot,
errorHandler: func(rw http.ResponseWriter, req *http.Request, err error) { rw.WriteHeader(http.StatusTeapot) },
errorHandler: func(rw http.ResponseWriter, _ *http.Request, _ error) { rw.WriteHeader(http.StatusTeapot) },
},
{
name: "modifyresponse_noerr",
Expand All @@ -706,7 +706,7 @@ func TestProxyErrorHandler(t *testing.T) {
res.StatusCode++
return nil
},
errorHandler: func(rw http.ResponseWriter, req *http.Request, err error) { rw.WriteHeader(http.StatusTeapot) },
errorHandler: func(rw http.ResponseWriter, _ *http.Request, _ error) { rw.WriteHeader(http.StatusTeapot) },
wantCode: 346,
},
{
Expand All @@ -718,7 +718,7 @@ func TestProxyErrorHandler(t *testing.T) {
res.StatusCode++
return errors.New("some error to trigger errorHandler")
},
errorHandler: func(rw http.ResponseWriter, req *http.Request, err error) { rw.WriteHeader(http.StatusTeapot) },
errorHandler: func(rw http.ResponseWriter, _ *http.Request, _ error) { rw.WriteHeader(http.StatusTeapot) },
wantCode: http.StatusTeapot,
},
}
Expand Down Expand Up @@ -756,7 +756,7 @@ func TestProxyErrorHandler(t *testing.T) {

// Issue 16659: log errors from short read
func TestProxy_CopyBuffer(t *testing.T) {
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
out := "this call was relayed by the reverse proxy"
// Coerce a wrong content length to induce io.UnexpectedEOF
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(out)*2))
Expand Down Expand Up @@ -815,7 +815,7 @@ func BenchmarkServeHTTP(b *testing.B) {
}

func TestServeHTTPDeepCopy(t *testing.T) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("Hello Gopher!"))
}))
defer backend.Close()
Expand Down Expand Up @@ -892,7 +892,7 @@ func TestModifyResponseClosesBody(t *testing.T) {
closeCheck := new(checkCloser)
outErr := errors.New("ModifyResponse error")
rp := &Proxy{
Director: func(req *http.Request) {},
Director: func(_ *http.Request) {},
Transport: &staticTransport{&http.Response{
StatusCode: 200,
Body: closeCheck,
Expand Down Expand Up @@ -929,7 +929,7 @@ func (cc *checkCloser) Read(b []byte) (int, error) {
func TestProxy_PanicBodyError(t *testing.T) {
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stderr)
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
out := "this call was relayed by the reverse proxy"
// Coerce a wrong content length to induce io.ErrUnexpectedEOF
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(out)*2))
Expand Down Expand Up @@ -970,7 +970,7 @@ func (b neverEnding) Read(p []byte) (n int, err error) {

// Issue #46866: panic without closing incoming request body causes a panic
func TestProxy_PanicClosesIncomingBody(t *testing.T) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
out := "this call was relayed by the reverse proxy"
// Coerce a wrong content length to induce io.ErrUnexpectedEOF
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(out)*2))
Expand Down Expand Up @@ -1222,7 +1222,7 @@ func TestProxyWebSocketCancellation(t *testing.T) {
}

func TestUnannouncedTrailer(t *testing.T) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.(http.Flusher).Flush()
w.Header().Set(http.TrailerPrefix+"X-Unannounced-Trailer", "unannounced_trailer_value")
Expand Down
Loading