Add GeoIP support for unique IP aggregation
Publish telemt-api gateway Docker image / test (push) Failing after 17s
Publish telemt-api gateway Docker image / build-and-push (push) Has been skipped

- 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.
This commit is contained in:
Denozordec
2026-03-30 01:47:08 +07:00
parent 4a4f15bd0b
commit d7a63f0da3
15 changed files with 449 additions and 12 deletions
+16 -1
View File
@@ -3,6 +3,7 @@ package main
import (
"context"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
@@ -10,6 +11,7 @@ import (
"time"
"github.com/telemt/telemt-api/internal/config"
"github.com/telemt/telemt-api/internal/geoip"
"github.com/telemt/telemt-api/internal/server"
)
@@ -31,7 +33,20 @@ func main() {
os.Exit(1)
}
gw, err := server.NewGateway(parsed, log)
geoDown := &http.Client{
Transport: &http.Transport{
DialContext: (&net.Dialer{Timeout: 30 * time.Second}).DialContext,
ResponseHeaderTimeout: 5 * time.Minute,
},
Timeout: 15 * time.Minute,
}
geo, err := geoip.FromConfig(parsed.Config.GeoIP, geoDown, log)
if err != nil {
log.Error("geoip init failed", "err", err)
os.Exit(1)
}
gw, err := server.NewGateway(parsed, log, geo)
if err != nil {
log.Error("gateway init failed", "err", err)
os.Exit(1)