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.
This commit is contained in:
+16
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user