diff --git a/agent/pkg/agent/stream/header.go b/agent/pkg/agent/stream/header.go index 2acdfeaf..b825fd1d 100644 --- a/agent/pkg/agent/stream/header.go +++ b/agent/pkg/agent/stream/header.go @@ -21,8 +21,10 @@ const ( var version = [versionSize]byte{'0', '.', '1', '.', '0', 0, 0, 0} -var ErrInvalidHeader = errors.New("invalid header") -var ErrCloseImmediately = errors.New("close immediately") +var ( + ErrInvalidHeader = errors.New("invalid header") + ErrCloseImmediately = errors.New("close immediately") +) type FlagType uint8 diff --git a/agent/pkg/agent/stream/tests/mux_test.go b/agent/pkg/agent/stream/tests/mux_test.go index 8bb5b455..c378aa90 100644 --- a/agent/pkg/agent/stream/tests/mux_test.go +++ b/agent/pkg/agent/stream/tests/mux_test.go @@ -45,9 +45,10 @@ func TestTLSALPNMux_HTTPAndStreamShareOnePort(t *testing.T) { defer func() { _ = tlsLn.Close() }() // HTTP server - httpSrv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - _, _ = w.Write([]byte("ok")) - }), + httpSrv := &http.Server{ + Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, _ = w.Write([]byte("ok")) + }), TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){ stream.StreamALPN: func(_ *http.Server, conn *tls.Conn, _ http.Handler) { streamSrv.ServeConn(conn) diff --git a/agent/pkg/agent/stream/tests/server_flow_test.go b/agent/pkg/agent/stream/tests/server_flow_test.go index f797a2b4..c962d4ea 100644 --- a/agent/pkg/agent/stream/tests/server_flow_test.go +++ b/agent/pkg/agent/stream/tests/server_flow_test.go @@ -102,7 +102,6 @@ func TestUDPServer_RejectInvalidClient(t *testing.T) { srv := startUDPServer(t, certs) - // Try to connect with a client cert from a different CA _, err = stream.NewUDPClient(srv.Addr.String(), dstAddr, certs.CaCert, invalidClientCert) require.Error(t, err, "expected error when connecting with client cert from different CA") diff --git a/cmd/bench_server/main.go b/cmd/bench_server/main.go index 92a64e01..51807d11 100644 --- a/cmd/bench_server/main.go +++ b/cmd/bench_server/main.go @@ -2,13 +2,14 @@ package main import ( "log" - "net/http" - "math/rand/v2" + "net/http" ) -var printables = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -var random = make([]byte, 4096) +var ( + printables = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + random = make([]byte, 4096) +) func init() { for i := range random { diff --git a/internal/autocert/config.go b/internal/autocert/config.go index e0af3b64..8d545cd2 100644 --- a/internal/autocert/config.go +++ b/internal/autocert/config.go @@ -23,33 +23,35 @@ import ( strutils "github.com/yusing/goutils/strings" ) -type ConfigExtra Config -type Config struct { - Email string `json:"email,omitempty"` - Domains []string `json:"domains,omitempty"` - CertPath string `json:"cert_path,omitempty"` - KeyPath string `json:"key_path,omitempty"` - Extra []ConfigExtra `json:"extra,omitempty"` - ACMEKeyPath string `json:"acme_key_path,omitempty"` // shared by all extra providers with the same CA directory URL - Provider string `json:"provider,omitempty"` - Options map[string]strutils.Redacted `json:"options,omitempty"` +type ( + ConfigExtra Config + Config struct { + Email string `json:"email,omitempty"` + Domains []string `json:"domains,omitempty"` + CertPath string `json:"cert_path,omitempty"` + KeyPath string `json:"key_path,omitempty"` + Extra []ConfigExtra `json:"extra,omitempty"` + ACMEKeyPath string `json:"acme_key_path,omitempty"` // shared by all extra providers with the same CA directory URL + Provider string `json:"provider,omitempty"` + Options map[string]strutils.Redacted `json:"options,omitempty"` - Resolvers []string `json:"resolvers,omitempty"` + Resolvers []string `json:"resolvers,omitempty"` - // Custom ACME CA - CADirURL string `json:"ca_dir_url,omitempty"` - CACerts []string `json:"ca_certs,omitempty"` + // Custom ACME CA + CADirURL string `json:"ca_dir_url,omitempty"` + CACerts []string `json:"ca_certs,omitempty"` - // EAB - EABKid string `json:"eab_kid,omitempty" validate:"required_with=EABHmac"` - EABHmac string `json:"eab_hmac,omitempty" validate:"required_with=EABKid"` // base64 encoded + // EAB + EABKid string `json:"eab_kid,omitempty" validate:"required_with=EABHmac"` + EABHmac string `json:"eab_hmac,omitempty" validate:"required_with=EABKid"` // base64 encoded - HTTPClient *http.Client `json:"-"` // for tests only + HTTPClient *http.Client `json:"-"` // for tests only - challengeProvider challenge.Provider + challengeProvider challenge.Provider - idx int // 0: main, 1+: extra[i] -} + idx int // 0: main, 1+: extra[i] + } +) var ( ErrMissingField = gperr.New("missing field") diff --git a/internal/autocert/provider_test/multi_cert_test.go b/internal/autocert/provider_test/multi_cert_test.go index f8ee18c1..c892c80b 100644 --- a/internal/autocert/provider_test/multi_cert_test.go +++ b/internal/autocert/provider_test/multi_cert_test.go @@ -68,7 +68,7 @@ func TestMultipleCertificatesLifecycle(t *testing.T) { require.Equal(t, "custom", cfg.Extra[1].Provider) /* track cert requests for all configs */ - os.MkdirAll("certs", 0755) + os.MkdirAll("certs", 0o755) defer os.RemoveAll("certs") err = provider.ObtainCertIfNotExistsAll() diff --git a/internal/health/check/http.go b/internal/health/check/http.go index d49c7fd2..6a597373 100644 --- a/internal/health/check/http.go +++ b/internal/health/check/http.go @@ -24,6 +24,7 @@ var h2cClient = &http.Client{ }, }, } + var pinger = &fasthttp.Client{ MaxConnDuration: 0, DisableHeaderNamesNormalizing: true, diff --git a/internal/logging/accesslog/console_logger.go b/internal/logging/accesslog/console_logger.go index 7651dceb..2ef02eb0 100644 --- a/internal/logging/accesslog/console_logger.go +++ b/internal/logging/accesslog/console_logger.go @@ -21,7 +21,8 @@ var stdoutLogger = func() *zerolog.Logger { w.FieldsOrder = []string{ "uri", "protocol", "type", "size", "useragent", "query", "headers", "cookies", - "error", "iso_code", "time_zone"} + "error", "iso_code", "time_zone", + } })).With().Str("level", zerolog.InfoLevel.String()).Timestamp().Logger() return &l }() diff --git a/internal/logging/accesslog/file_access_logger.go b/internal/logging/accesslog/file_access_logger.go index 17b45c9a..7f09dbba 100644 --- a/internal/logging/accesslog/file_access_logger.go +++ b/internal/logging/accesslog/file_access_logger.go @@ -63,8 +63,10 @@ const ( errBurst = 5 ) -var bytesPool = synk.GetUnsizedBytesPool() -var sizedPool = synk.GetSizedBytesPool() +var ( + bytesPool = synk.GetUnsizedBytesPool() + sizedPool = synk.GetSizedBytesPool() +) func NewFileAccessLogger(parent task.Parent, file File, anyCfg AnyConfig) AccessLogger { cfg := anyCfg.ToConfig() diff --git a/internal/net/gphttp/loadbalancer/ip_hash.go b/internal/net/gphttp/loadbalancer/ip_hash.go index 907646ac..7711f61f 100644 --- a/internal/net/gphttp/loadbalancer/ip_hash.go +++ b/internal/net/gphttp/loadbalancer/ip_hash.go @@ -19,8 +19,10 @@ type ipHash struct { mu sync.Mutex } -var _ impl = (*ipHash)(nil) -var _ customServeHTTP = (*ipHash)(nil) +var ( + _ impl = (*ipHash)(nil) + _ customServeHTTP = (*ipHash)(nil) +) func (lb *LoadBalancer) newIPHash() impl { impl := &ipHash{LoadBalancer: lb} diff --git a/internal/net/gphttp/loadbalancer/least_conn.go b/internal/net/gphttp/loadbalancer/least_conn.go index abc8a565..4ee0116f 100644 --- a/internal/net/gphttp/loadbalancer/least_conn.go +++ b/internal/net/gphttp/loadbalancer/least_conn.go @@ -13,8 +13,10 @@ type leastConn struct { nConn *xsync.Map[types.LoadBalancerServer, *atomic.Int64] } -var _ impl = (*leastConn)(nil) -var _ customServeHTTP = (*leastConn)(nil) +var ( + _ impl = (*leastConn)(nil) + _ customServeHTTP = (*leastConn)(nil) +) func (lb *LoadBalancer) newLeastConn() impl { return &leastConn{ diff --git a/internal/route/rules/http_flow_test.go b/internal/route/rules/http_flow_test.go index ae40edb4..2476ae6c 100644 --- a/internal/route/rules/http_flow_test.go +++ b/internal/route/rules/http_flow_test.go @@ -523,11 +523,11 @@ func TestHTTPFlow_ServeCommand(t *testing.T) { // The path /files/index.html gets mapped to tempDir + "/files/index.html" // We need to create the file at the expected path filesDir := filepath.Join(tempDir, "files") - err = os.Mkdir(filesDir, 0755) + err = os.Mkdir(filesDir, 0o755) require.NoError(t, err) filesIndexFile := filepath.Join(filesDir, "index.html") - err = os.WriteFile(filesIndexFile, []byte("