From d205f2bb35543834f077296c724cb304579ad7dc Mon Sep 17 00:00:00 2001 From: Mxmilu666 Date: Sat, 6 Jun 2026 11:35:40 +0800 Subject: [PATCH] chore(ci): update Go version and golangci-lint version feat(linter): add new linters G118 and G704 refactor(proxy): optimize proxy status slice initialization fix(api): clarify comment regarding URL construction fix(deps): upgrade github.com/hashicorp/yamux to v0.1.2 docs(flags): improve DNS server flag description refactor(controller): simplify port range return logic refactor(featuregate): optimize enabled features string conversion --- .github/workflows/golangci-lint.yml | 4 ++-- .golangci.yml | 2 ++ client/proxy/proxy_manager.go | 2 +- cmd/frpc/sub/root.go | 2 +- go.mod | 2 +- pkg/config/flags.go | 2 +- pkg/nathole/controller.go | 6 ++---- pkg/policy/featuregate/feature_gate.go | 5 +++-- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 0c8f8335..ba9706d8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.24' + go-version: '1.25' cache: false - uses: actions/setup-node@v4 with: @@ -32,4 +32,4 @@ jobs: uses: golangci/golangci-lint-action@v8 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v2.3 \ No newline at end of file + version: v2.11 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index f7c0e8bd..3a8a052a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,7 +39,9 @@ linters: - G404 - G501 - G115 + - G118 - G204 + - G704 severity: low confidence: low govet: diff --git a/client/proxy/proxy_manager.go b/client/proxy/proxy_manager.go index dd25e71e..e1372417 100644 --- a/client/proxy/proxy_manager.go +++ b/client/proxy/proxy_manager.go @@ -118,9 +118,9 @@ func (pm *Manager) HandleEvent(payload any) error { } func (pm *Manager) GetAllProxyStatus() []*WorkingStatus { - ps := make([]*WorkingStatus, 0) pm.mu.RLock() defer pm.mu.RUnlock() + ps := make([]*WorkingStatus, 0, len(pm.proxies)) for _, pxy := range pm.proxies { ps = append(ps, pxy.GetStatus()) } diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 11c6e467..23a2faa6 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -299,7 +299,7 @@ func runClientWithTokenAndIDs(token string, ids []string, unsafeFeatures *securi // Build URL with query parameters url := fmt.Sprintf("%s/api/v1/tunnel/frpc/config?token=%s&id=%s", apiServer, token, strings.Join(ids, ",")) - // #nosec G107 -- URL is constructed from trusted source (environment variable or hardcoded) + // URL is constructed from trusted source (environment variable or hardcoded) req, err := http.NewRequest("GET", url, nil) if err != nil { return fmt.Errorf("failed to create API request: %v", err) diff --git a/go.mod b/go.mod index 677f887e..2b07b8e4 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 github.com/gorilla/websocket v1.5.0 - github.com/hashicorp/yamux v0.1.1 + github.com/hashicorp/yamux v0.1.2 github.com/onsi/ginkgo/v2 v2.23.4 github.com/onsi/gomega v1.36.3 github.com/pelletier/go-toml/v2 v2.2.0 diff --git a/pkg/config/flags.go b/pkg/config/flags.go index b1849cd6..1491a14e 100644 --- a/pkg/config/flags.go +++ b/pkg/config/flags.go @@ -163,7 +163,7 @@ func RegisterClientCommonConfigFlags(cmd *cobra.Command, c *v1.ClientCommonConfi cmd.PersistentFlags().Int64VarP(&c.Log.MaxDays, "log_max_days", "", 3, "log file reversed days") cmd.PersistentFlags().BoolVarP(&c.Log.DisablePrintColor, "disable_log_color", "", false, "disable log color in console") cmd.PersistentFlags().StringVarP(&c.Transport.TLS.ServerName, "tls_server_name", "", "", "specify the custom server name of tls certificate") - cmd.PersistentFlags().StringVarP(&c.DNSServer, "dns_server", "", "", "specify dns server instead of using system default one, support DoH url like https://1.1.1.1/dns-query") + cmd.PersistentFlags().StringVarP(&c.DNSServer, "dns_server", "", "", "specify dns server or DoH url (https://1.1.1.1/dns-query) instead of system default") c.Transport.TLS.Enable = cmd.PersistentFlags().BoolP("tls_enable", "", true, "enable frpc tls") } cmd.PersistentFlags().StringVarP(&c.User, "user", "u", "", "user") diff --git a/pkg/nathole/controller.go b/pkg/nathole/controller.go index a1411317..d7f38020 100644 --- a/pkg/nathole/controller.go +++ b/pkg/nathole/controller.go @@ -375,7 +375,6 @@ func getRangePorts(addrs []string, difference, maxNumber int) []msg.PortsRange { if !isLast { return nil } - var ports []msg.PortsRange _, portStr, err := net.SplitHostPort(addr) if err != nil { return nil @@ -384,9 +383,8 @@ func getRangePorts(addrs []string, difference, maxNumber int) []msg.PortsRange { if err != nil { return nil } - ports = append(ports, msg.PortsRange{ + return []msg.PortsRange{{ From: max(port-difference-5, port-maxNumber, 1), To: min(port+difference+5, port+maxNumber, 65535), - }) - return ports + }} } diff --git a/pkg/policy/featuregate/feature_gate.go b/pkg/policy/featuregate/feature_gate.go index c5fd684b..81a392b7 100644 --- a/pkg/policy/featuregate/feature_gate.go +++ b/pkg/policy/featuregate/feature_gate.go @@ -171,8 +171,9 @@ func (f *featureGate) Add(features map[Feature]FeatureSpec) error { // String returns a string containing all enabled feature gates, formatted as "key1=value1,key2=value2,..." func (f *featureGate) String() string { - pairs := []string{} - for k, v := range f.enabled.Load().(map[Feature]bool) { + enabled := f.enabled.Load().(map[Feature]bool) + pairs := make([]string, 0, len(enabled)) + for k, v := range enabled { pairs = append(pairs, fmt.Sprintf("%s=%t", k, v)) } sort.Strings(pairs)