Refactor geo resources

This commit is contained in:
世界
2022-07-05 13:23:47 +08:00
parent 8392567962
commit 2d9203ee74
12 changed files with 273 additions and 198 deletions

View File

@@ -39,24 +39,14 @@ func (r *GeoIPItem) Match(metadata *adapter.InboundContext) bool {
}
if r.isSource {
if metadata.SourceGeoIPCode == "" {
country, err := geoReader.Country(metadata.Source.Addr.AsSlice())
if err != nil {
r.logger.Error("query geoip for ", metadata.Source.Addr, ": ", err)
return false
}
metadata.SourceGeoIPCode = strings.ToLower(country.Country.IsoCode)
metadata.SourceGeoIPCode = geoReader.Lookup(metadata.Source.Addr)
}
} else {
if metadata.Destination.IsFqdn() {
return false
}
if metadata.GeoIPCode == "" {
country, err := geoReader.Country(metadata.Destination.Addr.AsSlice())
if err != nil {
r.logger.Error("query geoip for ", metadata.Destination.Addr, ": ", err)
return false
}
metadata.GeoIPCode = strings.ToLower(country.Country.IsoCode)
metadata.GeoIPCode = geoReader.Lookup(metadata.Destination.Addr)
}
}
return r.match(metadata)