2.4 KiB
2.4 KiB
Repository Guidelines
Project Structure & Module Organization
cmd/server/main.gois the Fiber entrypoint that wires config, routes, and startup logging.internal/geoowns GeoLite2 lookups, IP validation, and response shaping.docker-compose.ymldefines the container entry;Dockerfilebuilds a static binary.GeoLite2-City.mmdbsits at the repo root and is mounted to/initial_data/GeoLite2-City.mmdb.- Keep
cmd/serverthin; place new logic ininternal/<domain>with clear boundaries.
Build, Test, and Development Commands
PORT=8080 GEOIP_DB_PATH=./GeoLite2-City.mmdb go run ./cmd/serverruns the API locally without Docker.docker compose up --buildbuilds and starts the containerized service (mounts the local database).curl "http://localhost:8080/lookup?ip=1.1.1.1"exercises the lookup endpoint; omitipto use the caller’s address.go build ./...validates compilation before pushing changes.
Coding Style & Naming Conventions
- Go 1.22; always format with
gofmt -w. - Favor small packages and dependency injection for services (e.g., pass resolvers, do not use globals).
- Package names are lowercase; exported identifiers use CamelCase; environment variables use UPPER_SNAKE.
- Keep JSON response shapes stable; prefer explicit structs over maps for API outputs.
Testing Guidelines
- Use Go’s standard testing with
*_test.gofiles and rungo test ./.... - Prefer table-driven tests for lookup edges (IPv4/IPv6, invalid IP, missing city/region data).
- For integration tests, allow overriding
GEOIP_DB_PATHwith a fixture.mmdbto avoid mutating the bundled dataset.
Commit & Pull Request Guidelines
- Commit titles should be concise, imperative English with an optional
scope (
geo,server,build). - Add a short body describing intent and behavioral impact when relevant.
- PR descriptions should list linked issues, test commands executed, and a sample request/response payload when API output changes.
- Keep images lean; avoid adding unused assets or oversized binaries to the image layers.
Security & Configuration Tips
- GeoLite2 carries licensing; refresh by replacing
GeoLite2-City.mmdbwith the latest download rather than mirroring it elsewhere. - Validate IP inputs and avoid logging full client IPs with stack traces in sensitive environments.
- Behind proxies, configure trusted proxy headers so
X-Forwarded-Foris respected (Fiberapp.Config.ProxyHeadercan be set if needed).