How afloresc/ipquery works
Purpose and runtime
IPQuery is a Go HTTP microservice that returns normalized IP intelligence, including ISP, geolocation, and risk data. It exposes a versioned REST API, fronts an external IP-information provider, caches results in process memory, and is containerizable for platforms such as Render.
Entry point and composition
cmd/server/main.go is the application entry point. It is responsible for process startup and wiring the HTTP router, IP-info service/provider, logging, and server configuration. The service is intended to bind using environment-provided port configuration, including Render’s PORT.
Paths:
• cmd/server/main.go
• Dockerfile
HTTP boundary and API routing
The HTTP layer owns public endpoints and request/response behavior:
• GET /v1/health provides liveness/operational status.
• GET /v1/ip/{ip} resolves intelligence for the requested IP.
Routing and HTTP-specific concerns are separated from domain lookup logic, so handlers translate inbound requests into service calls and serialize JSON responses/errors.
Paths:
• internal/handlers/routes.go
• internal/handlers/http.go
Request protection and middleware pipeline
Requests pass through operational and security middleware before reaching handlers. README-defined controls include structured request logging, panic recovery, strict timeouts, rate limiting, CORS restrictions, security headers, and client-IP handling via X-Forwarded-For protection. This is the principal trust boundary between internet-facing traffic and lookup execution.
Paths:
• internal/handlers/routes.go
• internal/logger/middleware.go
IP intelligence domain service
The IP-info layer contains the core lookup orchestration: it validates/uses the requested IP, checks cached data, calls the provider on a miss, and returns a unified result shape to handlers. This isolates external-provider-specific behavior from the API contract.
Paths:
• internal/ipinfo/service.go
• internal/ipinfo/provider.go
Caching and resilience boundary
Lookup results are cached in memory using sync.Map with a one-hour lifetime, reducing latency and external API dependence. Provider calls are guarded by strict timeouts; failures are surfaced through the HTTP layer rather than destabilizing the process. Cache state is local to one service instance and is lost on restart or not shared across replicas.
Paths:
• internal/ipinfo/service.go
• internal/ipinfo/provider.go
Observability and deployment
Logging is structured JSON using Go’s slog, implemented as HTTP middleware for cloud-log ingestion and request tracing/diagnosis. The Docker build artifact supports container deployment; Render is the documented target and consumes the health endpoint for service checks.
Paths:
• internal/logger/middleware.go
• Dockerfile
• cmd/server/main.go
Main entry points: routes.go API router · http.go HTTP handlers · service.go IP lookup service · main.go Server bootstrap
Components 11
Service Runtime
- Docker image · Container artifact for deployment platforms.
Dockerfile - Server bootstrap · Wires router, IP service, logging, and port configuration.
cmd/server/main.go
HTTP Boundary
- API router · Applies request protection before versioned endpoints.
internal/handlers/routes.go - HTTP handlers · Serves health and IP lookup JSON responses.
internal/handlers/http.go - Request logging · Emits structured JSON request logs.
internal/logger/middleware.go
IP Intelligence
- IP lookup service · Coordinates cache lookup, provider calls, and normalized results.
internal/ipinfo/service.go - In-memory cache · Per-instance results cached for one hour.
internal/ipinfo/service.go - Provider adapter · Executes timeout-bounded external intelligence requests.
internal/ipinfo/provider.go
External Systems
- Internet clients
- External IP provider
- Render platform · Supplies PORT and checks service health.
Connections 12
- Docker image → Server bootstrap: packages
- Render platform → Docker image: deploys
- Render platform → Server bootstrap: PORT
- Internet clients → API router: HTTP requests
- API router → Request logging: request logging
- API router → HTTP handlers: middleware-protected routes
- HTTP handlers → IP lookup service: GET /v1/ip/{ip}
- HTTP handlers → Render platform: GET /v1/health
- IP lookup service → In-memory cache: read/write results
- IP lookup service → Provider adapter: cache miss
- Provider adapter → External IP provider: timeout-bounded lookup
- Request logging → Server bootstrap: structured logs