From e5c59fc756a64926d5b7be7b1965e54d33cc9b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 24 Aug 2022 18:56:17 +0800 Subject: [PATCH] Fix lint --- Makefile | 15 ++++++++++++++- gvisor_err.go | 1 + monitor_android.go | 31 ++++++++++++++++--------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index db33160..77925e6 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,17 @@ fmt: fmt_install: go install -v mvdan.cc/gofumpt@latest - go install -v github.com/daixiang0/gci@v0.4.0 \ No newline at end of file + go install -v github.com/daixiang0/gci@v0.4.0 + +lint: + GOOS=linux golangci-lint run . + GOOS=android golangci-lint run . + GOOS=windows golangci-lint run . + GOOS=darwin golangci-lint run . + GOOS=freebsd golangci-lint run . + +lint_install: + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +test: + go test -v ./... \ No newline at end of file diff --git a/gvisor_err.go b/gvisor_err.go index 4964088..d2f016a 100644 --- a/gvisor_err.go +++ b/gvisor_err.go @@ -6,6 +6,7 @@ import ( "net" E "github.com/sagernet/sing/common/exceptions" + "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/adapters/gonet" ) diff --git a/monitor_android.go b/monitor_android.go index 735dab9..588e8ac 100644 --- a/monitor_android.go +++ b/monitor_android.go @@ -27,25 +27,26 @@ func (m *defaultInterfaceMonitor) checkUpdate() error { return err } - for _, route := range routes { - var link netlink.Link - link, err = netlink.LinkByIndex(route.LinkIndex) - if err != nil { - return err - } + if len(routes) == 0 { + return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex) + } - oldInterface := m.defaultInterfaceName - oldIndex := m.defaultInterfaceIndex + var link netlink.Link + link, err = netlink.LinkByIndex(routes[0].LinkIndex) + if err != nil { + return err + } - m.defaultInterfaceName = link.Attrs().Name - m.defaultInterfaceIndex = link.Attrs().Index + oldInterface := m.defaultInterfaceName + oldIndex := m.defaultInterfaceIndex - if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex { - return nil - } - m.emit() + m.defaultInterfaceName = link.Attrs().Name + m.defaultInterfaceIndex = link.Attrs().Index + + if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex { return nil } - return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex) + m.emit() + return nil }