Files
telemt-api/docs/GEOIP.md
T
Denozordec d7a63f0da3
Publish telemt-api gateway Docker image / test (push) Failing after 17s
Publish telemt-api gateway Docker image / build-and-push (push) Has been skipped
Add GeoIP support for unique IP aggregation
- Introduced GeoIP configuration options in config.example.yaml to enable geolocation lookups for the /api/agg/unique-ips endpoint.
- Updated the aggregate handler to include optional GeoIP data in responses, enriching unique IP information with country and city details, as well as ASN data if available.
- Enhanced documentation in AGGREGATE.md and README.md to reflect the new GeoIP functionality and its usage.
- Added a dependency on the geoip2-golang library in go.mod for GeoIP lookups.
- Modified tests to accommodate the new GeoIP integration in the aggregate handler.
2026-03-30 01:47:08 +07:00

43 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# GeoIP / GeoLite2 в шлюзе
При включённом **`geoip`** шлюз открывает один или два файла **MaxMind DB** (`.mmdb`) и обогащает ответ **`GET /api/agg/unique-ips`** (если не передан `?geo=false`).
## Нужны ли все три базы (City, Country, ASN)?
| База | Нужна ли отдельно | Зачем |
| --- | --- | --- |
| **GeoLite2-City** | Для геолокации — **да** (или только она) | Страна, город, англ. названия. |
| **GeoLite2-Country** | **Нет**, если есть City | В City уже есть страна; Country даёт только страну и **дублирует** часть данных City. |
| **GeoLite2-ASN** | **Опционально** | Номер автономной системы (ASN) и имя организации (провайдер/сеть), **не** заменяет город. |
Итого: минимум — **одна база City** для страны/города. Для «кто оператор сети» добавляют **ASN** (City + ASN вместе дают полную картину). **Three MMDB не обязательны** — достаточно **12 файлов** (City + при желании ASN).
## Поля в JSON
- Из **City**: `country_code`, `country_name`, `city_name`
- Из **ASN**: `asn`, `as_organization`
## Конфигурация
Нужен **хотя бы один** путь: `database_path` (City) и/или `asn_database_path` (ASN).
Пример с репозитория [P3TERX/GeoLite.mmdb](https://github.com/P3TERX/GeoLite.mmdb) (сырые `.mmdb` по HTTPS):
```yaml
geoip:
enabled: true
database_path: /var/lib/telemt-gateway/GeoLite2-City.mmdb
download_url: "https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb"
asn_database_path: /var/lib/telemt-gateway/GeoLite2-ASN.mmdb
asn_download_url: "https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-ASN.mmdb"
```
- Если локального файла нет, а указан соответствующий `*_download_url`, при старте выполняется загрузка.
- URL с суффиксом **`.gz`** обрабатываются как gzip; иначе тело ответа пишется в файл как есть (подходит для GitHub raw `.mmdb`).
## Лицензия
GeoLite2 распространяется MaxMind на условиях [лицензии](https://dev.maxmind.com/geoip/geolite2-free-data-feed). Сторонние зеркала и репозитории используйте на свой риск; для продакшена часто нужен свой ключ MaxMind и обновление БД.
Библиотека чтения: [`github.com/oschwald/geoip2-golang`](https://github.com/oschwald/geoip2-golang).