Fix lint errors

This commit is contained in:
世界
2026-05-13 22:37:05 +08:00
parent 429182a349
commit a47f39fa2b
79 changed files with 219 additions and 667 deletions

View File

@@ -112,7 +112,7 @@ func (c *CacheFile) Start(stage adapter.StartStage) error {
db *bbolt.DB
err error
)
for i := 0; i < 10; i++ {
for range 10 {
db, err = bbolt.Open(c.path, fileMode, &options)
if err == nil {
break

View File

@@ -164,7 +164,7 @@ func (s *Server) Start(stage adapter.StartStage) error {
listener net.Listener
err error
)
for i := 0; i < 3; i++ {
for range 3 {
listener, err = net.Listen("tcp", s.httpServer.Addr)
if runtime.GOOS == "android" && errors.Is(err, syscall.EADDRINUSE) {
time.Sleep(100 * time.Millisecond)

View File

@@ -147,7 +147,7 @@ func (c *CommandClient) dialWithRetry(target string, contextDialer func(context.
var client daemon.StartedServiceClient
var lastError error
for attempt := 0; attempt < commandClientDialAttempts; attempt++ {
for attempt := range commandClientDialAttempts {
if connection == nil {
options := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),

View File

@@ -114,7 +114,7 @@ func (s *CommandServer) Start() error {
if sCommandServerListenPort == 0 {
sockPath := filepath.Join(sBasePath, "command.sock")
os.Remove(sockPath)
for i := 0; i < 30; i++ {
for range 30 {
listener, err = net.ListenUnix("unix", &net.UnixAddr{
Name: sockPath,
Net: "unix",

View File

@@ -418,13 +418,3 @@ func systemProxyStatusFromGRPC(status *daemon.SystemProxyStatus) *SystemProxySta
Enabled: status.Enabled,
}
}
func systemProxyStatusToGRPC(status *SystemProxyStatus) *daemon.SystemProxyStatus {
if status == nil {
return nil
}
return &daemon.SystemProxyStatus{
Available: status.Available,
Enabled: status.Enabled,
}
}

View File

@@ -8,8 +8,6 @@ import (
"runtime/debug"
)
var crashOutputFile *os.File
func RedirectStderr(path string) error {
if stats, err := os.Stat(path); err == nil && stats.Size() > 0 {
_ = os.Rename(path, path+".old")
@@ -32,6 +30,5 @@ func RedirectStderr(path string) error {
os.Remove(outputFile.Name())
return err
}
crashOutputFile = outputFile
return nil
return outputFile.Close()
}

View File

@@ -16,7 +16,6 @@ var (
type platformDefaultInterfaceMonitor struct {
*platformInterfaceWrapper
logger logger.Logger
element *list.Element[tun.NetworkUpdateCallback]
callbacks list.List[tun.DefaultInterfaceUpdateCallback]
myInterface string
}

View File

@@ -1,9 +1,6 @@
package libbox
import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
)
import C "github.com/sagernet/sing-box/constant"
type PlatformInterface interface {
LocalDNSTransport() LocalDNSTransport
@@ -98,37 +95,3 @@ type OnDemandRuleIterator interface {
Next() OnDemandRule
HasNext() bool
}
type onDemandRule struct {
option.OnDemandRule
}
func (r *onDemandRule) Target() int32 {
if r.OnDemandRule.Action == nil {
return -1
}
return int32(*r.OnDemandRule.Action)
}
func (r *onDemandRule) DNSSearchDomainMatch() StringIterator {
return newIterator(r.OnDemandRule.DNSSearchDomainMatch)
}
func (r *onDemandRule) DNSServerAddressMatch() StringIterator {
return newIterator(r.OnDemandRule.DNSServerAddressMatch)
}
func (r *onDemandRule) InterfaceTypeMatch() int32 {
if r.OnDemandRule.InterfaceTypeMatch == nil {
return -1
}
return int32(*r.OnDemandRule.InterfaceTypeMatch)
}
func (r *onDemandRule) SSIDMatch() StringIterator {
return newIterator(r.OnDemandRule.SSIDMatch)
}
func (r *onDemandRule) ProbeURL() string {
return r.OnDemandRule.ProbeURL
}

View File

@@ -11,7 +11,7 @@ const utunControlName = "com.apple.net.utun_control"
func GetTunnelFileDescriptor() int32 {
ctlInfo := &unix.CtlInfo{}
copy(ctlInfo.Name[:], utunControlName)
for fd := 0; fd < 1024; fd++ {
for fd := range 1024 {
addr, err := unix.Getpeername(fd)
if err != nil {
continue