From e7150ba254dd4caf33d52193a401c3fc9f46e9bb Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sat, 27 May 2023 15:22:13 +0000 Subject: [PATCH] chore(settings): remove unused settings helpers --- .../configuration/settings/dnsblacklist.go | 2 +- .../configuration/settings/helpers/copy.go | 20 ------ .../configuration/settings/helpers/default.go | 39 ----------- .../settings/helpers/generics.go | 10 --- .../configuration/settings/helpers/merge.go | 69 ------------------- .../settings/helpers/override.go | 52 -------------- 6 files changed, 1 insertion(+), 191 deletions(-) delete mode 100644 internal/configuration/settings/helpers/copy.go delete mode 100644 internal/configuration/settings/helpers/default.go delete mode 100644 internal/configuration/settings/helpers/generics.go delete mode 100644 internal/configuration/settings/helpers/merge.go delete mode 100644 internal/configuration/settings/helpers/override.go diff --git a/internal/configuration/settings/dnsblacklist.go b/internal/configuration/settings/dnsblacklist.go index f3f87d1e..eef7d924 100644 --- a/internal/configuration/settings/dnsblacklist.go +++ b/internal/configuration/settings/dnsblacklist.go @@ -68,7 +68,7 @@ func (b *DNSBlacklist) mergeWith(other DNSBlacklist) { b.BlockMalicious = gosettings.MergeWithPointer(b.BlockMalicious, other.BlockMalicious) b.BlockAds = gosettings.MergeWithPointer(b.BlockAds, other.BlockAds) b.BlockSurveillance = gosettings.MergeWithPointer(b.BlockSurveillance, other.BlockSurveillance) - b.AllowedHosts = helpers.MergeWithSlice(b.AllowedHosts, other.AllowedHosts) + b.AllowedHosts = gosettings.MergeWithSlice(b.AllowedHosts, other.AllowedHosts) b.AddBlockedHosts = gosettings.MergeWithSlice(b.AddBlockedHosts, other.AddBlockedHosts) b.AddBlockedIPs = gosettings.MergeWithSlice(b.AddBlockedIPs, other.AddBlockedIPs) b.AddBlockedIPPrefixes = gosettings.MergeWithSlice(b.AddBlockedIPPrefixes, other.AddBlockedIPPrefixes) diff --git a/internal/configuration/settings/helpers/copy.go b/internal/configuration/settings/helpers/copy.go deleted file mode 100644 index 13e52eea..00000000 --- a/internal/configuration/settings/helpers/copy.go +++ /dev/null @@ -1,20 +0,0 @@ -package helpers - -import ( - "net/netip" - - "golang.org/x/exp/slices" -) - -func CopyPointer[T any](original *T) (copied *T) { - if original == nil { - return nil - } - copied = new(T) - *copied = *original - return copied -} - -func CopySlice[T string | uint16 | netip.Addr | netip.Prefix](original []T) (copied []T) { - return slices.Clone(original) -} diff --git a/internal/configuration/settings/helpers/default.go b/internal/configuration/settings/helpers/default.go deleted file mode 100644 index bfa27d0b..00000000 --- a/internal/configuration/settings/helpers/default.go +++ /dev/null @@ -1,39 +0,0 @@ -package helpers - -import ( - "net/netip" -) - -func DefaultPointer[T any](existing *T, defaultValue T) ( - result *T) { - if existing != nil { - return existing - } - result = new(T) - *result = defaultValue - return result -} - -func DefaultString(existing string, defaultValue string) ( - result string) { - if existing != "" { - return existing - } - return defaultValue -} - -func DefaultNumber[T Number](existing T, defaultValue T) ( //nolint:ireturn - result T) { - if existing != 0 { - return existing - } - return defaultValue -} - -func DefaultValidator(existing netip.Addr, defaultValue netip.Addr) ( - result netip.Addr) { - if existing.IsValid() { - return existing - } - return defaultValue -} diff --git a/internal/configuration/settings/helpers/generics.go b/internal/configuration/settings/helpers/generics.go deleted file mode 100644 index 3faa86f5..00000000 --- a/internal/configuration/settings/helpers/generics.go +++ /dev/null @@ -1,10 +0,0 @@ -package helpers - -import "time" - -type Number interface { - uint8 | uint16 | uint32 | uint64 | uint | - int8 | int16 | int32 | int64 | int | - float32 | float64 | - time.Duration -} diff --git a/internal/configuration/settings/helpers/merge.go b/internal/configuration/settings/helpers/merge.go deleted file mode 100644 index 58ac8e14..00000000 --- a/internal/configuration/settings/helpers/merge.go +++ /dev/null @@ -1,69 +0,0 @@ -package helpers - -import ( - "net/http" - "net/netip" -) - -func MergeWithPointer[T any](existing, other *T) (result *T) { - if existing != nil { - return existing - } else if other == nil { - return nil - } - result = new(T) - *result = *other - return result -} - -func MergeWithString(existing, other string) (result string) { - if existing != "" { - return existing - } - return other -} - -func MergeWithNumber[T Number](existing, other T) (result T) { //nolint:ireturn - if existing != 0 { - return existing - } - return other -} - -func MergeWithValidator(existing, other netip.Addr) (result netip.Addr) { - if existing.IsValid() { - return existing - } - return other -} - -func MergeWithHTTPHandler(existing, other http.Handler) (result http.Handler) { - if existing != nil { - return existing - } - return other -} - -func MergeWithSlice[T comparable](a, b []T) (result []T) { - if a == nil && b == nil { - return nil - } - - seen := make(map[T]struct{}, len(a)+len(b)) - result = make([]T, 0, len(a)+len(b)) - for _, s := range a { - if _, ok := seen[s]; ok { - continue // duplicate - } - result = append(result, s) - seen[s] = struct{}{} - } - for _, s := range b { - if _, ok := seen[s]; ok { - continue // duplicate - } - result = append(result, s) - seen[s] = struct{}{} - } - return result -} diff --git a/internal/configuration/settings/helpers/override.go b/internal/configuration/settings/helpers/override.go deleted file mode 100644 index 81630d58..00000000 --- a/internal/configuration/settings/helpers/override.go +++ /dev/null @@ -1,52 +0,0 @@ -package helpers - -import ( - "net/http" - "net/netip" -) - -func OverrideWithPointer[T any](existing, other *T) (result *T) { - if other == nil { - return existing - } - result = new(T) - *result = *other - return result -} - -func OverrideWithString(existing, other string) (result string) { - if other == "" { - return existing - } - return other -} - -func OverrideWithNumber[T Number](existing, other T) (result T) { //nolint:ireturn - if other == 0 { - return existing - } - return other -} - -func OverrideWithValidator(existing, other netip.Addr) (result netip.Addr) { - if !other.IsValid() { - return existing - } - return other -} - -func OverrideWithHTTPHandler(existing, other http.Handler) (result http.Handler) { - if other != nil { - return other - } - return existing -} - -func OverrideWithSlice[T any](existing, other []T) (result []T) { - if other == nil { - return existing - } - result = make([]T, len(other)) - copy(result, other) - return result -}