diff --git a/internal/api/root.go b/internal/api/root.go index f7ade32..81a605e 100644 --- a/internal/api/root.go +++ b/internal/api/root.go @@ -333,16 +333,21 @@ func NewApi(ctx context.Context, WorkerManager *worker.Manager, HostManager *hos return nil, err } - log.Infof("Checking IP %s", args[0]) + if !a.GeoDatabase.IsValid() { + return "", nil + } + + log.Tracef("Checking geo:iso IP %s", args[0]) val := net.ParseIP(args[0]) if val == nil { return nil, fmt.Errorf("invalid IP") } + record, err := a.GeoDatabase.GetCity(&val) if err != nil && !errors.Is(err, geo.NotValidConfig) { - return nil, err + return "", err } return geo.GetIsoCodeFromRecord(record), nil diff --git a/internal/geo/root.go b/internal/geo/root.go index db3fe48..d7df384 100644 --- a/internal/geo/root.go +++ b/internal/geo/root.go @@ -86,11 +86,6 @@ func (g *GeoDatabase) IsValid() bool { } func (g *GeoDatabase) GetASN(ip *net.IP) (*geoip2.ASN, error) { - - if !g.IsValid() { - return nil, NotValidConfig - } - g.RLock() defer g.RUnlock() record := &geoip2.ASN{} @@ -104,11 +99,6 @@ func (g *GeoDatabase) GetASN(ip *net.IP) (*geoip2.ASN, error) { } func (g *GeoDatabase) GetCity(ip *net.IP) (*geoip2.City, error) { - - if !g.IsValid() { - return nil, NotValidConfig - } - g.RLock() defer g.RUnlock() record := &geoip2.City{}