Skip to content

Commit

Permalink
chore: bump golangci version
Browse files Browse the repository at this point in the history
Fix linting issues.
  • Loading branch information
Choraden committed Feb 7, 2024
1 parent a027f12 commit b54e528
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GO_VERSION=1.22.0

X_TOOLS_VERSION=v0.15.0
GOLANGCI_LINT_VERSION=v1.55.2
GOLANGCI_LINT_VERSION=v1.56.0
GORELEASER_VERSION=v1.22.1
GO_LICENSES_VERSION=v1.6.0

Expand Down
2 changes: 1 addition & 1 deletion bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func HTTPServerConfig(fs *pflag.FlagSet, cfg *forwarder.HTTPServerConfig, prefix
func HTTPLogConfig(fs *pflag.FlagSet, cfg []NamedParam[httplog.Mode]) {
for _, p := range cfg {
if p.Param == nil {
panic(fmt.Sprintf("httplog mode is nil for %s", p.Name))
panic("httplog mode is nil for %s" + p.Name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion bind/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func RedactUserinfo(ui *url.Userinfo) string {
return ""
}
if _, has := ui.Password(); has {
return fmt.Sprintf("%s:xxxxx", ui.Username())
return ui.Username() + ":xxxxx"
}
return ui.Username()
}
Expand Down
21 changes: 11 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package forwarder

import (
"errors"
"fmt"
"net"
"net/netip"
Expand All @@ -24,7 +25,7 @@ import (
// ParseUserinfo parses a user:password string into *url.Userinfo.
func ParseUserinfo(val string) (*url.Userinfo, error) {
if val == "" {
return nil, fmt.Errorf("expected username[:password]")
return nil, errors.New("expected username[:password]")
}

var ui *url.Userinfo
Expand All @@ -46,7 +47,7 @@ func validatedUserInfo(ui *url.Userinfo) error {
return nil
}
if ui.Username() == "" {
return fmt.Errorf("username cannot be empty")
return errors.New("username cannot be empty")
}

return nil
Expand All @@ -63,15 +64,15 @@ func wildcardPortTo0(val string) string {
// ParseHostPortUser parses a user:password@host:port string into HostUser.
func ParseHostPortUser(val string) (*HostPortUser, error) {
if val == "" {
return nil, fmt.Errorf("expected user[:password]@host:port")
return nil, errors.New("expected user[:password]@host:port")
}
if strings.Index(val, "@") != strings.LastIndex(val, "@") {
return nil, fmt.Errorf("only one '@' is allowed")
return nil, errors.New("only one '@' is allowed")
}

up, hp, ok := strings.Cut(val, "@")
if !ok {
return nil, fmt.Errorf("expected user[:password]@host:port")
return nil, errors.New("expected user[:password]@host:port")
}

ui, err := ParseUserinfo(up)
Expand Down Expand Up @@ -104,7 +105,7 @@ func ParseProxyURL(val string) (*url.URL, error) {
}

if strings.Index(hpu, "@") != strings.LastIndex(hpu, "@") {
return nil, fmt.Errorf("only one '@' is allowed")
return nil, errors.New("only one '@' is allowed")
}

var (
Expand Down Expand Up @@ -162,7 +163,7 @@ func validateProxyURL(u *url.URL) error {
uu := *u
uu.User = nil
if uu.String() != c.String() {
return fmt.Errorf("unsupported URL elements, format: [<protocol>://]<host>:<port>")
return errors.New("unsupported URL elements, format: [<protocol>://]<host>:<port>")
}
}

Expand All @@ -182,14 +183,14 @@ func validateProxyURL(u *url.URL) error {

{
if u.Port() == "" {
return fmt.Errorf("port is required")
return errors.New("port is required")
}
p, err := strconv.ParseUint(u.Port(), 10, 16)
if err != nil {
return fmt.Errorf("port: %w", err)
}
if p == 0 {
return fmt.Errorf("port cannot be 0")
return errors.New("port cannot be 0")
}
}

Expand Down Expand Up @@ -233,7 +234,7 @@ func validateDNSAddress(p netip.AddrPort) error {
return fmt.Errorf("IP: %s", p.Addr())
}
if p.Port() == 0 {
return fmt.Errorf("port cannot be 0")
return errors.New("port cannot be 0")
}
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package forwarder

import (
"errors"
"fmt"
"net"
"net/url"
Expand All @@ -22,13 +23,13 @@ type HostPortUser struct {

func (hpu *HostPortUser) Validate() error {
if hpu.Host == "" {
return fmt.Errorf("missing host")
return errors.New("missing host")
}
if hpu.Port == "" {
return fmt.Errorf("missing port")
return errors.New("missing port")
}
if hpu.Userinfo == nil {
return fmt.Errorf("missing user")
return errors.New("missing user")
}
return validatedUserInfo(hpu.Userinfo)
}
Expand Down Expand Up @@ -100,7 +101,7 @@ func NewCredentialsMatcher(credentials []*HostPortUser, log log.Logger) (*Creden
switch {
case hpu.Host == "*" && hpu.Port == "0":
if m.global != nil {
return nil, withRowInfo(fmt.Errorf("duplicate global input"))
return nil, withRowInfo(errors.New("duplicate global input"))
}
m.global = hpu.Userinfo
case hpu.Host == "*":
Expand All @@ -116,7 +117,7 @@ func NewCredentialsMatcher(credentials []*HostPortUser, log log.Logger) (*Creden
default:
hostport := net.JoinHostPort(hpu.Host, hpu.Port)
if _, ok := m.hostport[hostport]; ok {
return nil, fmt.Errorf("duplicate input")
return nil, errors.New("duplicate input")
}
m.hostport[hostport] = hpu.Userinfo
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/setup/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package setup

import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -40,7 +41,7 @@ func makeTestCallback(run string, debug bool) func() error {
fmt.Fprintln(os.Stderr, "stderr:")
stderr.WriteTo(os.Stderr)
fmt.Fprintln(os.Stderr)
return fmt.Errorf("unexpected stderr")
return errors.New("unexpected stderr")
}

s := strings.Split(stdout.String(), "\n")
Expand Down
2 changes: 1 addition & 1 deletion http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func newHTTPProxy(cfg *HTTPProxyConfig, pr PACResolver, cm *CredentialsMatcher,
return nil, err
}
if cfg.UpstreamProxy != nil && pr != nil {
return nil, fmt.Errorf("cannot use both upstream proxy and PAC")
return nil, errors.New("cannot use both upstream proxy and PAC")
}

// If not set, use http.DefaultTransport.
Expand Down
3 changes: 1 addition & 2 deletions http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package forwarder
import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestAbortIf(t *testing.T) {
}

func TestNopDialer(t *testing.T) {
nopDialerErr := fmt.Errorf("nop dialer")
nopDialerErr := errors.New("nop dialer")

tr := &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
Expand Down
2 changes: 1 addition & 1 deletion httplog/httplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (w *logWriter) ShortURLLine(e middleware.LogEntry) {
if scheme != "" {
scheme += "://"
}
if len(path) > 0 && path[0] != '/' {
if path != "" && path[0] != '/' {
path = "/" + path
}

Expand Down
7 changes: 4 additions & 3 deletions internal/martian/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package martian
import (
"bufio"
"context"
"errors"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -116,7 +117,7 @@ func (s *Session) Hijack() (conn net.Conn, brw *bufio.ReadWriter, err error) {
defer s.mu.Unlock()

if s.hijacked {
return nil, nil, fmt.Errorf("session has already been hijacked")
return nil, nil, errors.New("session has already been hijacked")
}
defer func() {
s.hijacked = err == nil
Expand All @@ -138,15 +139,15 @@ func (s *Session) HijackResponseWriter() (http.ResponseWriter, error) {
defer s.mu.Unlock()

if s.hijacked {
return nil, fmt.Errorf("session has already been hijacked")
return nil, errors.New("session has already been hijacked")
}

if s.rw != nil {
s.hijacked = true
return s.rw, nil
}

return nil, fmt.Errorf("session has no response writer")
return nil, errors.New("session has no response writer")
}

// Hijacked returns whether the connection has been hijacked.
Expand Down
2 changes: 1 addition & 1 deletion internal/martian/h2/h2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (p *plusOne) Message(data []byte, streamEnded bool) error {
if err := proto.Unmarshal(data, msg); err != nil {
return fmt.Errorf("unmarshalling request: %w", err)
}
msg.Values = append(msg.Values, 1) //nolint:protogetter // synthetic data
msg.Values = append(msg.Values, 1)

data, err := proto.Marshal(msg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/martian/h2/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func New(spf []h2.StreamProcessorFactory) (*Fixture, error) {
}
proxyTarget := hostname + ":" + strconv.Itoa(proxyPort)
// Sets the HTTPS_PROXY environment variable so that http requests will go through the proxy.
os.Setenv("HTTPS_PROXY", fmt.Sprintf("http://%s", proxyTarget))
os.Setenv("HTTPS_PROXY", "http://"+proxyTarget)
fmt.Printf("proxy at %s\n", proxyTarget)
}
if f.proxyListener == nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/martian/header/framing_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package header

import (
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -66,7 +67,7 @@ func NewBadFramingModifier() martian.RequestModifier {
// "chunked", else we have no way to determine when the request is
// finished.
if strings.TrimSpace(last[len(last)-1]) != "chunked" {
return fmt.Errorf(`bad request framing: "Transfer-Encoding" header is present, but does not end in "chunked"`)
return errors.New(`bad request framing: "Transfer-Encoding" header is present, but does not end in "chunked"`)
}

// Transfer-Encoding "chunked" takes precedence over
Expand Down
4 changes: 2 additions & 2 deletions internal/martian/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func TestIntegrationTLSHandshakeErrorCallback(t *testing.T) {
}

var herr error
mc.SetHandshakeErrorCallback(func(_ *http.Request, err error) { herr = fmt.Errorf("handshake error") })
mc.SetHandshakeErrorCallback(func(_ *http.Request, err error) { herr = errors.New("handshake error") })
p.SetMITM(mc)

tl, err := net.Listen("tcp", "[::]:0")
Expand Down Expand Up @@ -1808,7 +1808,7 @@ func TestServerClosesConnection(t *testing.T) {
}
defer conn.Close()

req, err := http.NewRequest(http.MethodConnect, fmt.Sprintf("//%s", dstl.Addr().String()), http.NoBody)
req, err := http.NewRequest(http.MethodConnect, "//"+dstl.Addr().String(), http.NoBody)
if err != nil {
t.Fatalf("http.NewRequest(): got %v, want no error", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/martian/proxyutil/proxyutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package proxyutil

import (
"fmt"
"errors"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestNewResponse(t *testing.T) {

func TestWarning(t *testing.T) {
hdr := http.Header{}
err := fmt.Errorf("modifier error")
err := errors.New("modifier error")

Warning(hdr, err)

Expand Down
4 changes: 2 additions & 2 deletions middleware/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package middleware

import (
"fmt"
"errors"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -138,7 +138,7 @@ func (p *Prometheus) ModifyResponse(res *http.Response) error {
start := t0.(time.Time) //nolint:forcetypeassert // we know it's time
elapsed = float64(time.Since(start)) / float64(time.Second)
} else {
return fmt.Errorf("prometheus duration key not found")
return errors.New("prometheus duration key not found")
}

reqSize := computeApproximateRequestSize(r)
Expand Down
4 changes: 2 additions & 2 deletions mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package forwarder
import (
"crypto/tls"
"crypto/x509"
"fmt"
"errors"
"time"

"github.com/saucelabs/forwarder/internal/martian/mitm"
Expand Down Expand Up @@ -53,7 +53,7 @@ func newMartianMITMConfig(c *MITMConfig) (*mitm.Config, error) {
}

if !ca.IsCA {
return nil, fmt.Errorf("certificate is not a CA")
return nil, errors.New("certificate is not a CA")
}

cfg, err := mitm.NewConfig(ca, cert.PrivateKey)
Expand Down
7 changes: 4 additions & 3 deletions pac/pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package pac

import (
"context"
"errors"
"fmt"
"io"
"net"
Expand All @@ -28,7 +29,7 @@ type ProxyResolverConfig struct {

func (c *ProxyResolverConfig) Validate() error {
if c.Script == "" {
return fmt.Errorf("PAC script is empty")
return errors.New("PAC script is empty")
}
return nil
}
Expand Down Expand Up @@ -82,10 +83,10 @@ func NewProxyResolver(cfg *ProxyResolverConfig, r *net.Resolver, opts ...Option)
// Find the FindProxyForURL function.
fnx, fn := pr.entryPoint()
if fnx == nil && fn == nil {
return nil, fmt.Errorf("PAC script: missing required function FindProxyForURL or FindProxyForURLEx")
return nil, errors.New("PAC script: missing required function FindProxyForURL or FindProxyForURLEx")
}
if fnx != nil && fn != nil {
return nil, fmt.Errorf("PAC script: ambiguous entry point, both FindProxyForURL and FindProxyForURLEx are defined")
return nil, errors.New("PAC script: ambiguous entry point, both FindProxyForURL and FindProxyForURLEx are defined")
}
if fnx != nil {
pr.fn = fnx
Expand Down
Loading

0 comments on commit b54e528

Please sign in to comment.