From 4cd4747525bc4be523ead8a0bd061026378eef24 Mon Sep 17 00:00:00 2001 From: fatedier Date: Thu, 8 Oct 2026 22:28:31 +0800 Subject: [PATCH] fix: use Go 1.26 new expressions for pointer initialization (#5559) --- client/service_test.go | 4 +--- pkg/config/legacy/conversion.go | 14 ++++++-------- pkg/config/v1/client.go | 8 ++++---- pkg/config/v1/proxy_plugin.go | 6 ++---- pkg/config/v1/server.go | 4 ++-- server/http/controller_v2_test.go | 10 +++------- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/client/service_test.go b/client/service_test.go index 29f141a1..cae26da3 100644 --- a/client/service_test.go +++ b/client/service_test.go @@ -9,8 +9,6 @@ import ( "strings" "testing" - "github.com/samber/lo" - "github.com/fatedier/frp/pkg/config/source" v1 "github.com/fatedier/frp/pkg/config/v1" ) @@ -49,7 +47,7 @@ func TestRunStopsStartedComponentsOnInitialLoginFailure(t *testing.T) { svr, err := NewService(ServiceOptions{ Common: &v1.ClientCommonConfig{ - LoginFailExit: lo.ToPtr(true), + LoginFailExit: new(true), WebServer: v1.WebServerConfig{ Addr: "127.0.0.1", Port: port, diff --git a/pkg/config/legacy/conversion.go b/pkg/config/legacy/conversion.go index ec8d0698..f394fea4 100644 --- a/pkg/config/legacy/conversion.go +++ b/pkg/config/legacy/conversion.go @@ -17,8 +17,6 @@ package legacy import ( "strings" - "github.com/samber/lo" - "github.com/fatedier/frp/pkg/config/types" v1 "github.com/fatedier/frp/pkg/config/v1" ) @@ -49,7 +47,7 @@ func Convert_ClientCommonConf_To_v1(conf *ClientCommonConf) *v1.ClientCommonConf out.Transport.ConnectServerLocalIP = conf.ConnectServerLocalIP out.Transport.ProxyURL = conf.HTTPProxy out.Transport.PoolCount = conf.PoolCount - out.Transport.TCPMux = lo.ToPtr(conf.TCPMux) + out.Transport.TCPMux = new(conf.TCPMux) out.Transport.TCPMuxKeepaliveInterval = conf.TCPMuxKeepaliveInterval out.Transport.Protocol = conf.Protocol out.Transport.HeartbeatInterval = conf.HeartbeatInterval @@ -57,8 +55,8 @@ func Convert_ClientCommonConf_To_v1(conf *ClientCommonConf) *v1.ClientCommonConf out.Transport.QUIC.KeepalivePeriod = conf.QUICKeepalivePeriod out.Transport.QUIC.MaxIdleTimeout = conf.QUICMaxIdleTimeout out.Transport.QUIC.MaxIncomingStreams = conf.QUICMaxIncomingStreams - out.Transport.TLS.Enable = lo.ToPtr(conf.TLSEnable) - out.Transport.TLS.DisableCustomTLSFirstByte = lo.ToPtr(conf.DisableCustomTLSFirstByte) + out.Transport.TLS.Enable = new(conf.TLSEnable) + out.Transport.TLS.DisableCustomTLSFirstByte = new(conf.DisableCustomTLSFirstByte) out.Transport.TLS.CertFile = conf.TLSCertFile out.Transport.TLS.KeyFile = conf.TLSKeyFile out.Transport.TLS.TrustedCaFile = conf.TLSTrustedCaFile @@ -77,7 +75,7 @@ func Convert_ClientCommonConf_To_v1(conf *ClientCommonConf) *v1.ClientCommonConf out.WebServer.PprofEnable = conf.PprofEnable out.DNSServer = conf.DNSServer - out.LoginFailExit = lo.ToPtr(conf.LoginFailExit) + out.LoginFailExit = new(conf.LoginFailExit) out.Start = conf.Start out.UDPPacketSize = conf.UDPPacketSize out.Metadatas = conf.Metas @@ -134,14 +132,14 @@ func Convert_ServerCommonConf_To_v1(conf *ServerCommonConf) *v1.ServerConfig { out.Log.MaxDays = conf.LogMaxDays out.Log.DisablePrintColor = conf.DisableLogColor - out.DetailedErrorsToClient = lo.ToPtr(conf.DetailedErrorsToClient) + out.DetailedErrorsToClient = new(conf.DetailedErrorsToClient) out.SubDomainHost = conf.SubDomainHost out.Custom404Page = conf.Custom404Page out.UserConnTimeout = conf.UserConnTimeout out.UDPPacketSize = conf.UDPPacketSize out.NatHoleAnalysisDataReserveHours = conf.NatHoleAnalysisDataReserveHours - out.Transport.TCPMux = lo.ToPtr(conf.TCPMux) + out.Transport.TCPMux = new(conf.TCPMux) out.Transport.TCPMuxKeepaliveInterval = conf.TCPMuxKeepaliveInterval out.Transport.TCPKeepAlive = conf.TCPKeepAlive out.Transport.MaxPoolCount = conf.MaxPoolCount diff --git a/pkg/config/v1/client.go b/pkg/config/v1/client.go index 05d02c94..6736030a 100644 --- a/pkg/config/v1/client.go +++ b/pkg/config/v1/client.go @@ -85,7 +85,7 @@ type ClientCommonConfig struct { func (c *ClientCommonConfig) Complete() error { c.ServerAddr = util.EmptyOr(c.ServerAddr, "0.0.0.0") c.ServerPort = util.EmptyOr(c.ServerPort, 7000) - c.LoginFailExit = util.EmptyOr(c.LoginFailExit, lo.ToPtr(true)) + c.LoginFailExit = util.EmptyOr(c.LoginFailExit, new(true)) c.NatHoleSTUNServer = util.EmptyOr(c.NatHoleSTUNServer, "stun.easyvoip.com:3478") if err := c.Auth.Complete(); err != nil { @@ -151,7 +151,7 @@ func (c *ClientTransportConfig) Complete() { c.DialServerKeepAlive = util.EmptyOr(c.DialServerKeepAlive, 7200) c.ProxyURL = util.EmptyOr(c.ProxyURL, os.Getenv("http_proxy")) c.PoolCount = util.EmptyOr(c.PoolCount, 1) - c.TCPMux = util.EmptyOr(c.TCPMux, lo.ToPtr(true)) + c.TCPMux = util.EmptyOr(c.TCPMux, new(true)) c.TCPMuxKeepaliveInterval = util.EmptyOr(c.TCPMuxKeepaliveInterval, 30) if lo.FromPtr(c.TCPMux) { // If TCPMux is enabled, heartbeat of application layer is unnecessary because we can rely on heartbeat in tcpmux. @@ -180,8 +180,8 @@ type TLSClientConfig struct { } func (c *TLSClientConfig) Complete() { - c.Enable = util.EmptyOr(c.Enable, lo.ToPtr(true)) - c.DisableCustomTLSFirstByte = util.EmptyOr(c.DisableCustomTLSFirstByte, lo.ToPtr(true)) + c.Enable = util.EmptyOr(c.Enable, new(true)) + c.DisableCustomTLSFirstByte = util.EmptyOr(c.DisableCustomTLSFirstByte, new(true)) } type AuthClientConfig struct { diff --git a/pkg/config/v1/proxy_plugin.go b/pkg/config/v1/proxy_plugin.go index 0d6ca3d0..7c63c2f9 100644 --- a/pkg/config/v1/proxy_plugin.go +++ b/pkg/config/v1/proxy_plugin.go @@ -17,8 +17,6 @@ package v1 import ( "reflect" - "github.com/samber/lo" - "github.com/fatedier/frp/pkg/util/jsonx" "github.com/fatedier/frp/pkg/util/util" ) @@ -125,7 +123,7 @@ type HTTPS2HTTPPluginOptions struct { } func (o *HTTPS2HTTPPluginOptions) Complete() { - o.EnableHTTP2 = util.EmptyOr(o.EnableHTTP2, lo.ToPtr(true)) + o.EnableHTTP2 = util.EmptyOr(o.EnableHTTP2, new(true)) } func (o *HTTPS2HTTPPluginOptions) Clone() ClientPluginOptions { @@ -149,7 +147,7 @@ type HTTPS2HTTPSPluginOptions struct { } func (o *HTTPS2HTTPSPluginOptions) Complete() { - o.EnableHTTP2 = util.EmptyOr(o.EnableHTTP2, lo.ToPtr(true)) + o.EnableHTTP2 = util.EmptyOr(o.EnableHTTP2, new(true)) } func (o *HTTPS2HTTPSPluginOptions) Clone() ClientPluginOptions { diff --git a/pkg/config/v1/server.go b/pkg/config/v1/server.go index 67c1d84b..6c1c75c4 100644 --- a/pkg/config/v1/server.go +++ b/pkg/config/v1/server.go @@ -118,7 +118,7 @@ func (c *ServerConfig) Complete() error { } c.VhostHTTPTimeout = util.EmptyOr(c.VhostHTTPTimeout, 60) - c.DetailedErrorsToClient = util.EmptyOr(c.DetailedErrorsToClient, lo.ToPtr(true)) + c.DetailedErrorsToClient = util.EmptyOr(c.DetailedErrorsToClient, new(true)) c.UserConnTimeout = util.EmptyOr(c.UserConnTimeout, 10) c.UDPPacketSize = util.EmptyOr(c.UDPPacketSize, 1500) c.NatHoleAnalysisDataReserveHours = util.EmptyOr(c.NatHoleAnalysisDataReserveHours, 7*24) @@ -180,7 +180,7 @@ type ServerTransportConfig struct { } func (c *ServerTransportConfig) Complete() { - c.TCPMux = util.EmptyOr(c.TCPMux, lo.ToPtr(true)) + c.TCPMux = util.EmptyOr(c.TCPMux, new(true)) c.TCPMuxKeepaliveInterval = util.EmptyOr(c.TCPMuxKeepaliveInterval, 30) c.TCPKeepAlive = util.EmptyOr(c.TCPKeepAlive, 7200) c.MaxPoolCount = util.EmptyOr(c.MaxPoolCount, 5) diff --git a/server/http/controller_v2_test.go b/server/http/controller_v2_test.go index 042cedbc..6a233a36 100644 --- a/server/http/controller_v2_test.go +++ b/server/http/controller_v2_test.go @@ -615,7 +615,7 @@ func TestMatchV2ProxyQueryMatchesSpecFields(t *testing.T) { name: "tcp remote port", item: model.V2ProxyResp{Name: "tcp-proxy", Spec: model.V2ProxySpec{ Type: "tcp", - TCP: &model.V2TCPProxySpec{RemotePort: v2TestIntPtr(6000)}, + TCP: &model.V2TCPProxySpec{RemotePort: new(6000)}, }}, q: "6000", want: true, @@ -624,7 +624,7 @@ func TestMatchV2ProxyQueryMatchesSpecFields(t *testing.T) { name: "udp remote port", item: model.V2ProxyResp{Name: "udp-proxy", Spec: model.V2ProxySpec{ Type: "udp", - UDP: &model.V2UDPProxySpec{RemotePort: v2TestIntPtr(7000)}, + UDP: &model.V2UDPProxySpec{RemotePort: new(7000)}, }}, q: "7000", want: true, @@ -633,7 +633,7 @@ func TestMatchV2ProxyQueryMatchesSpecFields(t *testing.T) { name: "remote port does not match colon form", item: model.V2ProxyResp{Name: "tcp-proxy", Spec: model.V2ProxySpec{ Type: "tcp", - TCP: &model.V2TCPProxySpec{RemotePort: v2TestIntPtr(6000)}, + TCP: &model.V2TCPProxySpec{RemotePort: new(6000)}, }}, q: ":6000", want: false, @@ -767,10 +767,6 @@ func TestLegacyAPIResponsesRemainBare(t *testing.T) { } } -func v2TestIntPtr(value int) *int { - return &value -} - func newV2TestController(t *testing.T) *Controller { t.Helper()