Skip to content

feat: IP geolocation service (ip66.dev MMDB) #12

@chendingplano

Description

@chendingplano

Summary

Add a shared IP geolocation service backed by the free ip66.dev MMDB database (CC BY 4.0, no API key required).

Changes

New package: shared/go/api/ipdb/

File Purpose
types.go IPRecord, SyncStatus, internal mmdbRecord
store.go PostgreSQL table creation, cache CRUD, sync log
lookup.go Hot-swappable MMDB reader, LookupIP with cache
sync.go Daily download scheduler, atomic file replacement, Init/Shutdown

New handler file: shared/go/api/RequestHandlers/ipdb_handlers.go

  • HandleIPLookupGET /shared_api/v1/ipdb/lookup?ip=<addr>
  • HandleIPSyncStatusGET /shared_api/v1/ipdb/sync/status
  • HandleIPSyncTriggerPOST /shared_api/v1/ipdb/sync/trigger (admin)

Modified files

  • api/sysdatastores/createtables.go — calls ipdb.CreateTables(logger)
  • api/router.go — registers the three new endpoints
  • go.mod / go.sum — adds github.com/oschwald/maxminddb-golang v1.13.1

New documentation

shared/Documents/services/ipdb/README.md

Database tables

  • ipdb_lookup_cache — caches recent lookups (configurable TTL, default 7 days)
  • ipdb_sync_log — audit trail of every sync attempt

Configuration

Env var Default Description
IPDB_FILE_PATH /var/data/ip66.mmdb Local MMDB file path
IPDB_CACHE_TTL_DAYS 7 Lookup cache TTL

Integration steps for consuming projects

Call ipdb.Init(logger) once at startup (after sysdatastores.CreateSysTables), and ipdb.Shutdown() on graceful stop.

sysdatastores.CreateSysTables(logger)
ipdb.Init(logger)
defer ipdb.Shutdown()

Data provided per IP

  • ASN number + organisation name
  • Country name + ISO 3166-1 alpha-2 code
  • Continent name + two-letter code
  • IPv4 and IPv6 supported

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions