From 73c30590e015f55e3de0a01f98a3c79761dce3b7 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Tue, 8 Dec 2020 16:01:13 +0300 Subject: [PATCH] Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 --- internal/agherr/agherr.go | 6 ++++++ internal/agherr/agherr_test.go | 2 ++ internal/dnsfilter/dnsfilter.go | 11 ----------- internal/sysutil/syslog_others.go | 3 ++- internal/sysutil/syslog_windows.go | 2 +- internal/util/{auto_hosts.go => autohosts.go} | 0 .../util/{auto_hosts_test.go => autohosts_test.go} | 0 internal/util/helpers.go | 8 -------- internal/util/{network_utils.go => network.go} | 0 .../util/{network_utils_test.go => network_test.go} | 3 +-- 10 files changed, 12 insertions(+), 23 deletions(-) rename internal/util/{auto_hosts.go => autohosts.go} (100%) rename internal/util/{auto_hosts_test.go => autohosts_test.go} (100%) rename internal/util/{network_utils.go => network.go} (100%) rename internal/util/{network_utils_test.go => network_test.go} (92%) diff --git a/internal/agherr/agherr.go b/internal/agherr/agherr.go index dee29466..aedf2a8b 100644 --- a/internal/agherr/agherr.go +++ b/internal/agherr/agherr.go @@ -65,3 +65,9 @@ func (e *manyError) Unwrap() error { return e.underlying[0] } + +// wrapper is a copy of the hidden errors.wrapper interface for tests, linting, +// etc. +type wrapper interface { + Unwrap() error +} diff --git a/internal/agherr/agherr_test.go b/internal/agherr/agherr_test.go index 8ef2f51f..123c45ef 100644 --- a/internal/agherr/agherr_test.go +++ b/internal/agherr/agherr_test.go @@ -41,6 +41,8 @@ func TestError_Error(t *testing.T) { } func TestError_Unwrap(t *testing.T) { + var _ wrapper = &manyError{} + const ( errSimple = iota errWrapped diff --git a/internal/dnsfilter/dnsfilter.go b/internal/dnsfilter/dnsfilter.go index 855bbf60..340bfaaf 100644 --- a/internal/dnsfilter/dnsfilter.go +++ b/internal/dnsfilter/dnsfilter.go @@ -129,8 +129,6 @@ const ( NotFilteredNotFound Reason = iota // NotFilteredWhiteList - the host is explicitly whitelisted NotFilteredWhiteList - // NotFilteredError - there was a transitive error during check - NotFilteredError // reasons for filtering @@ -777,12 +775,3 @@ func (d *Dnsfilter) Start() { d.registerBlockedServicesHandlers() } } - -// -// stats -// - -// GetStats return dns filtering stats since startup. -func (d *Dnsfilter) GetStats() Stats { - return gctx.stats -} diff --git a/internal/sysutil/syslog_others.go b/internal/sysutil/syslog_others.go index 12c8a803..0e0e1c3f 100644 --- a/internal/sysutil/syslog_others.go +++ b/internal/sysutil/syslog_others.go @@ -3,8 +3,9 @@ package sysutil import ( - "log" "log/syslog" + + "github.com/AdguardTeam/golibs/log" ) func configureSyslog(serviceName string) error { diff --git a/internal/sysutil/syslog_windows.go b/internal/sysutil/syslog_windows.go index f83eab80..2160ea43 100644 --- a/internal/sysutil/syslog_windows.go +++ b/internal/sysutil/syslog_windows.go @@ -3,9 +3,9 @@ package sysutil import ( - "log" "strings" + "github.com/AdguardTeam/golibs/log" "golang.org/x/sys/windows" "golang.org/x/sys/windows/svc/eventlog" ) diff --git a/internal/util/auto_hosts.go b/internal/util/autohosts.go similarity index 100% rename from internal/util/auto_hosts.go rename to internal/util/autohosts.go diff --git a/internal/util/auto_hosts_test.go b/internal/util/autohosts_test.go similarity index 100% rename from internal/util/auto_hosts_test.go rename to internal/util/autohosts_test.go diff --git a/internal/util/helpers.go b/internal/util/helpers.go index e023da08..2770fa44 100644 --- a/internal/util/helpers.go +++ b/internal/util/helpers.go @@ -9,7 +9,6 @@ import ( "io/ioutil" "os" "os/exec" - "path" "runtime" "strings" ) @@ -41,13 +40,6 @@ func RunCommand(command string, arguments ...string) (int, string, error) { return cmd.ProcessState.ExitCode(), string(out), nil } -func FuncName() string { - pc := make([]uintptr, 10) // at least 1 entry needed - runtime.Callers(2, pc) - f := runtime.FuncForPC(pc[0]) - return path.Base(f.Name()) -} - // SplitNext - split string by a byte and return the first chunk // Skip empty chunks // Whitespace is trimmed diff --git a/internal/util/network_utils.go b/internal/util/network.go similarity index 100% rename from internal/util/network_utils.go rename to internal/util/network.go diff --git a/internal/util/network_utils_test.go b/internal/util/network_test.go similarity index 92% rename from internal/util/network_utils_test.go rename to internal/util/network_test.go index 7feac0f2..9b2a9554 100644 --- a/internal/util/network_utils_test.go +++ b/internal/util/network_test.go @@ -1,7 +1,6 @@ package util import ( - "log" "testing" ) @@ -19,6 +18,6 @@ func TestGetValidNetInterfacesForWeb(t *testing.T) { t.Fatalf("No addresses found for %s", iface.Name) } - log.Printf("%v", iface) + t.Logf("%v", iface) } }