From c72f66d64b4f92c60f2603d2ec12385139e8e951 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 26 Apr 2025 09:48:43 +0800 Subject: [PATCH] feat(acl): add FORCE_RESOLVE_COUNTRY option to resolve country --- internal/acl/config.go | 8 ++++++-- internal/common/env.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/acl/config.go b/internal/acl/config.go index b47bfd44..1bbe147a 100644 --- a/internal/acl/config.go +++ b/internal/acl/config.go @@ -9,6 +9,7 @@ import ( "github.com/puzpuzpuz/xsync/v3" "github.com/rs/zerolog" acl "github.com/yusing/go-proxy/internal/acl/types" + "github.com/yusing/go-proxy/internal/common" "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/logging" "github.com/yusing/go-proxy/internal/logging/accesslog" @@ -153,7 +154,10 @@ func (c *Config) Start(parent *task.Task) gperr.Error { return nil } -func (c *config) cacheRecord(info *acl.IPInfo, allow bool) { +func (c *Config) cacheRecord(info *acl.IPInfo, allow bool) { + if common.ForceResolveCountry && info.City == nil { + c.MaxMind.lookupCity(info) + } c.ipCache.Store(info.Str, &checkCache{ IPInfo: info, allow: allow, @@ -175,7 +179,7 @@ func (c *Config) IPAllowed(ip net.IP) bool { return false } - // always allow private and loopback + // always allow loopback // loopback is not logged if ip.IsLoopback() { return true diff --git a/internal/common/env.go b/internal/common/env.go index 73df1951..ccfda821 100644 --- a/internal/common/env.go +++ b/internal/common/env.go @@ -58,6 +58,8 @@ var ( MetricsDisableDisk = GetEnvBool("METRICS_DISABLE_DISK", false) MetricsDisableNetwork = GetEnvBool("METRICS_DISABLE_NETWORK", false) MetricsDisableSensors = GetEnvBool("METRICS_DISABLE_SENSORS", false) + + ForceResolveCountry = GetEnvBool("FORCE_RESOLVE_COUNTRY", false) ) func GetEnv[T any](key string, defaultValue T, parser func(string) (T, error)) T {