From d7b150732858e98a563a89fa331fbc481e45f4ee Mon Sep 17 00:00:00 2001 From: Maxim Kurbatov Date: Sun, 17 Nov 2024 19:09:29 +0500 Subject: [PATCH] Make code compatible with golang 1.20 to support armv7-2.6 and x86-2.6 --- go.mod | 2 +- lib/router.go | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index dcc9761..e786ea7 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module maksimkurb/keenetic-pbr -go 1.22 +go 1.20 require github.com/BurntSushi/toml v1.4.0 diff --git a/lib/router.go b/lib/router.go index a2872d8..ab172e2 100644 --- a/lib/router.go +++ b/lib/router.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" "regexp" - "slices" + "sort" "strings" ) @@ -118,8 +118,7 @@ func ApplyLists(config *Config) error { } defer f.Close() - slices.Sort(domains) - domains = slices.Compact(domains) + domains = removeDuplicates(domains) writer := bufio.NewWriter(f) for _, domain := range domains { @@ -134,3 +133,19 @@ func ApplyLists(config *Config) error { log.Print("Configuration applied successfully") return nil } + +func removeDuplicates(strings []string) []string { + sort.Strings(strings) + // Remove duplicates + if len(strings) > 0 { + j := 1 + for i := 1; i < len(strings); i++ { + if strings[i] != strings[i-1] { + strings[j] = strings[i] + j++ + } + } + strings = strings[:j] + } + return strings +}