chore: apply golangci-lint fmt

This commit is contained in:
yusing
2026-02-21 12:56:51 +08:00
parent ee973f7997
commit dea37a437b
14 changed files with 57 additions and 45 deletions

View File

@@ -21,8 +21,10 @@ const (
var version = [versionSize]byte{'0', '.', '1', '.', '0', 0, 0, 0} var version = [versionSize]byte{'0', '.', '1', '.', '0', 0, 0, 0}
var ErrInvalidHeader = errors.New("invalid header") var (
var ErrCloseImmediately = errors.New("close immediately") ErrInvalidHeader = errors.New("invalid header")
ErrCloseImmediately = errors.New("close immediately")
)
type FlagType uint8 type FlagType uint8

View File

@@ -45,9 +45,10 @@ func TestTLSALPNMux_HTTPAndStreamShareOnePort(t *testing.T) {
defer func() { _ = tlsLn.Close() }() defer func() { _ = tlsLn.Close() }()
// HTTP server // HTTP server
httpSrv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { httpSrv := &http.Server{
_, _ = w.Write([]byte("ok")) Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
}), _, _ = w.Write([]byte("ok"))
}),
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){ TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){
stream.StreamALPN: func(_ *http.Server, conn *tls.Conn, _ http.Handler) { stream.StreamALPN: func(_ *http.Server, conn *tls.Conn, _ http.Handler) {
streamSrv.ServeConn(conn) streamSrv.ServeConn(conn)

View File

@@ -102,7 +102,6 @@ func TestUDPServer_RejectInvalidClient(t *testing.T) {
srv := startUDPServer(t, certs) srv := startUDPServer(t, certs)
// Try to connect with a client cert from a different CA // Try to connect with a client cert from a different CA
_, err = stream.NewUDPClient(srv.Addr.String(), dstAddr, certs.CaCert, invalidClientCert) _, err = stream.NewUDPClient(srv.Addr.String(), dstAddr, certs.CaCert, invalidClientCert)
require.Error(t, err, "expected error when connecting with client cert from different CA") require.Error(t, err, "expected error when connecting with client cert from different CA")

View File

@@ -2,13 +2,14 @@ package main
import ( import (
"log" "log"
"net/http"
"math/rand/v2" "math/rand/v2"
"net/http"
) )
var printables = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" var (
var random = make([]byte, 4096) printables = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
random = make([]byte, 4096)
)
func init() { func init() {
for i := range random { for i := range random {

View File

@@ -23,33 +23,35 @@ import (
strutils "github.com/yusing/goutils/strings" strutils "github.com/yusing/goutils/strings"
) )
type ConfigExtra Config type (
type Config struct { ConfigExtra Config
Email string `json:"email,omitempty"` Config struct {
Domains []string `json:"domains,omitempty"` Email string `json:"email,omitempty"`
CertPath string `json:"cert_path,omitempty"` Domains []string `json:"domains,omitempty"`
KeyPath string `json:"key_path,omitempty"` CertPath string `json:"cert_path,omitempty"`
Extra []ConfigExtra `json:"extra,omitempty"` KeyPath string `json:"key_path,omitempty"`
ACMEKeyPath string `json:"acme_key_path,omitempty"` // shared by all extra providers with the same CA directory URL Extra []ConfigExtra `json:"extra,omitempty"`
Provider string `json:"provider,omitempty"` ACMEKeyPath string `json:"acme_key_path,omitempty"` // shared by all extra providers with the same CA directory URL
Options map[string]strutils.Redacted `json:"options,omitempty"` 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 // Custom ACME CA
CADirURL string `json:"ca_dir_url,omitempty"` CADirURL string `json:"ca_dir_url,omitempty"`
CACerts []string `json:"ca_certs,omitempty"` CACerts []string `json:"ca_certs,omitempty"`
// EAB // EAB
EABKid string `json:"eab_kid,omitempty" validate:"required_with=EABHmac"` EABKid string `json:"eab_kid,omitempty" validate:"required_with=EABHmac"`
EABHmac string `json:"eab_hmac,omitempty" validate:"required_with=EABKid"` // base64 encoded 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 ( var (
ErrMissingField = gperr.New("missing field") ErrMissingField = gperr.New("missing field")

View File

@@ -68,7 +68,7 @@ func TestMultipleCertificatesLifecycle(t *testing.T) {
require.Equal(t, "custom", cfg.Extra[1].Provider) require.Equal(t, "custom", cfg.Extra[1].Provider)
/* track cert requests for all configs */ /* track cert requests for all configs */
os.MkdirAll("certs", 0755) os.MkdirAll("certs", 0o755)
defer os.RemoveAll("certs") defer os.RemoveAll("certs")
err = provider.ObtainCertIfNotExistsAll() err = provider.ObtainCertIfNotExistsAll()

View File

@@ -24,6 +24,7 @@ var h2cClient = &http.Client{
}, },
}, },
} }
var pinger = &fasthttp.Client{ var pinger = &fasthttp.Client{
MaxConnDuration: 0, MaxConnDuration: 0,
DisableHeaderNamesNormalizing: true, DisableHeaderNamesNormalizing: true,

View File

@@ -21,7 +21,8 @@ var stdoutLogger = func() *zerolog.Logger {
w.FieldsOrder = []string{ w.FieldsOrder = []string{
"uri", "protocol", "type", "size", "uri", "protocol", "type", "size",
"useragent", "query", "headers", "cookies", "useragent", "query", "headers", "cookies",
"error", "iso_code", "time_zone"} "error", "iso_code", "time_zone",
}
})).With().Str("level", zerolog.InfoLevel.String()).Timestamp().Logger() })).With().Str("level", zerolog.InfoLevel.String()).Timestamp().Logger()
return &l return &l
}() }()

View File

@@ -63,8 +63,10 @@ const (
errBurst = 5 errBurst = 5
) )
var bytesPool = synk.GetUnsizedBytesPool() var (
var sizedPool = synk.GetSizedBytesPool() bytesPool = synk.GetUnsizedBytesPool()
sizedPool = synk.GetSizedBytesPool()
)
func NewFileAccessLogger(parent task.Parent, file File, anyCfg AnyConfig) AccessLogger { func NewFileAccessLogger(parent task.Parent, file File, anyCfg AnyConfig) AccessLogger {
cfg := anyCfg.ToConfig() cfg := anyCfg.ToConfig()

View File

@@ -19,8 +19,10 @@ type ipHash struct {
mu sync.Mutex mu sync.Mutex
} }
var _ impl = (*ipHash)(nil) var (
var _ customServeHTTP = (*ipHash)(nil) _ impl = (*ipHash)(nil)
_ customServeHTTP = (*ipHash)(nil)
)
func (lb *LoadBalancer) newIPHash() impl { func (lb *LoadBalancer) newIPHash() impl {
impl := &ipHash{LoadBalancer: lb} impl := &ipHash{LoadBalancer: lb}

View File

@@ -13,8 +13,10 @@ type leastConn struct {
nConn *xsync.Map[types.LoadBalancerServer, *atomic.Int64] nConn *xsync.Map[types.LoadBalancerServer, *atomic.Int64]
} }
var _ impl = (*leastConn)(nil) var (
var _ customServeHTTP = (*leastConn)(nil) _ impl = (*leastConn)(nil)
_ customServeHTTP = (*leastConn)(nil)
)
func (lb *LoadBalancer) newLeastConn() impl { func (lb *LoadBalancer) newLeastConn() impl {
return &leastConn{ return &leastConn{

View File

@@ -523,11 +523,11 @@ func TestHTTPFlow_ServeCommand(t *testing.T) {
// The path /files/index.html gets mapped to tempDir + "/files/index.html" // The path /files/index.html gets mapped to tempDir + "/files/index.html"
// We need to create the file at the expected path // We need to create the file at the expected path
filesDir := filepath.Join(tempDir, "files") filesDir := filepath.Join(tempDir, "files")
err = os.Mkdir(filesDir, 0755) err = os.Mkdir(filesDir, 0o755)
require.NoError(t, err) require.NoError(t, err)
filesIndexFile := filepath.Join(filesDir, "index.html") filesIndexFile := filepath.Join(filesDir, "index.html")
err = os.WriteFile(filesIndexFile, []byte("<h1>Test Page</h1>"), 0644) err = os.WriteFile(filesIndexFile, []byte("<h1>Test Page</h1>"), 0o644)
require.NoError(t, err) require.NoError(t, err)
req1 := httptest.NewRequest(http.MethodGet, "/files/index.html", nil) req1 := httptest.NewRequest(http.MethodGet, "/files/index.html", nil)

View File

@@ -46,7 +46,7 @@ func BenchmarkRules(b *testing.B) {
}) })
b.Run("RunHandler", func(b *testing.B) { b.Run("RunHandler", func(b *testing.B) {
var r = &http.Request{ r := &http.Request{
Body: io.NopCloser(bytes.NewReader([]byte(""))), Body: io.NopCloser(bytes.NewReader([]byte(""))),
URL: &url.URL{Path: "/api/users/"}, URL: &url.URL{Path: "/api/users/"},
} }
@@ -59,8 +59,7 @@ func BenchmarkRules(b *testing.B) {
}) })
} }
type noopResponseWriter struct { type noopResponseWriter struct{}
}
func (w noopResponseWriter) Header() http.Header { func (w noopResponseWriter) Header() http.Header {
return http.Header{} return http.Header{}

View File

@@ -61,7 +61,7 @@ func (cfg *DockerProviderConfig) Parse(value string) error {
func (cfg *DockerProviderConfig) UnmarshalMap(m map[string]any) error { func (cfg *DockerProviderConfig) UnmarshalMap(m map[string]any) error {
var tmp DockerProviderConfigDetailed var tmp DockerProviderConfigDetailed
var err = serialization.MapUnmarshalValidate(m, &tmp) err := serialization.MapUnmarshalValidate(m, &tmp)
if err != nil { if err != nil {
return err return err
} }