Commit graph

358 commits

Author SHA1 Message Date
ns
abbdb05709
feat: graceful shutdown on SIGINT/SIGTERM
main now uses signal.NotifyContext to cancel a root context on
SIGINT or SIGTERM. Both the public and debug listeners share that
context; on cancellation each calls srv.Shutdown with a 30s
timeout to drain in-flight requests before exiting.

If either listener fails the other is signalled to shut down too,
and the process exits 1. Bad CLI args now exit 2 (was 0).

Adds TestGracefulShutdown which fires a slow request, cancels the
context mid-flight, and asserts the request completes successfully
and the server returns nil.
2026-05-07 07:21:07 +00:00
ns
fe098d6357
refactor(http): replace hand-rolled router with stdlib ServeMux
Go 1.22+ ServeMux supports method matching, path wildcards, and
subtree patterns natively, making the bespoke router redundant.

- Delete http/router.go (-73 lines).
- Use 'METHOD /path' patterns and {port} wildcard for /port/.
- Content negotiation for / moved into rootHandler() dispatched
  via 'GET /{$}' (exact-match) — Accept header / cliMatcher /
  template availability decide which handler runs.
- muxNotFoundWrapper preserves content-negotiated 404 behaviour
  by detecting empty pattern from mux.Handler(r) and routing to
  NotFoundHandler.
- PortHandler now reads r.PathValue("port").

Net -41 lines, no external behaviour change. All tests pass.
2026-05-07 07:18:36 +00:00
ns
ec4366dc2e
github actions pinning 2026-05-07 07:10:45 +00:00
ns
da1995a1f4
chore: harden Makefile and Dockerfile
Makefile:
- Add .PHONY declaration for all 16 phony targets.
- Fix parse-time $(error) at line 39: replace with runtime shell
  check so the guard actually fires when the recipe runs.
- Simplify check-fmt to portable 'gofmt -l -s .' form.
- Add -trimpath -ldflags='-s -w' to install for smaller,
  reproducible binaries.

Dockerfile:
- Switch runtime to distroless/static-debian13:nonroot + USER nonroot.
- Split COPY so go.mod/go.sum cache layer is independent of source.
- Drop ENV GO111MODULE=on (no-op since Go 1.16).
2026-05-07 07:09:35 +00:00
ns
7f4bee21c2
refactor(geo): drop pointless zero-value defensive checks
Country/City/ASN had ~11 'if x != "" { y = x }' wrappers around
fields whose targets were already zero-valued. Replaced with
unconditional assignment and cmp.Or for genuine fallback chains
(Country -> RegisteredCountry). Kept guards that prevent real
panics (nil pointer, NaN, slice index).
2026-05-07 07:09:35 +00:00
ns
2a060db9df
refactor(http): collapse 6 duplicated CLI handlers into one helper
CLICountryHandler, CLICountryISOHandler, CLICityHandler,
CLICoordinatesHandler, CLIASNHandler, and CLIASNOrgHandler were
near-identical: call newResponse, return badRequest on error,
fmt.Fprintln a single field. Replaced with cliField(extract func)
and inline closures at route registration. -41 lines, no behavior
change.
2026-05-07 07:09:35 +00:00
ns
bcc8618003
chore: tighten .gitignore and .dockerignore
Add /x and Go build artifacts to .gitignore. Replace the minimal
.dockerignore with an explicit deny list excluding .git, *.mmdb,
data/, vendor/, docs, and build artifacts to shrink build context.

Note: GeoLite2-*.mmdb files still exist in older history; run
git filter-repo separately to purge them per MaxMind EULA.
2026-05-07 07:07:12 +00:00
ns
190c99f78b
fix(geo): mount routes per available DB, not all-or-nothing
IsEmpty() ignored the ASN reader, so launching with only an ASN
DB silently disabled all geo routes including /asn. Reader gains
HasCountry/HasCity/HasASN; http.Handler mounts each set
independently.
2026-05-07 07:07:08 +00:00
ns
29746d5c99
fix(cache): make cache truly LRU and resize correctly
Get() never promoted accessed entries, so eviction was insertion
order (FIFO), not LRU. Get() now MoveToBacks the element; cache
mu becomes sync.Mutex.

Resize() updated capacity but never evicted to fit the new size,
and incorrectly reset the evictions counter. It now evicts from
the front until len(entries) <= capacity and preserves the counter.

Also cleaned up the Set() eviction loop and added tests for LRU
promotion, immediate-shrink resize, and concurrent access.
2026-05-07 07:07:08 +00:00
ns
27957c928f
security: split pprof onto private listener and add HTTP timeouts
The -P flag previously mounted /debug/pprof and /debug/cache on
the public :8080 listener. pprof.Profile pegs a CPU for 30s
(unauthenticated DoS) and /debug/cache/resize was world-writable.

- -P changes from bool to string addr (e.g. 127.0.0.1:6060).
  When set, a second http.Server serves DebugHandler() on that addr.
- Public ListenAndServe now uses an explicit *http.Server with
  ReadHeaderTimeout=5s, ReadTimeout=10s, WriteTimeout=15s,
  IdleTimeout=60s to mitigate slowloris.
- http.New() no longer takes the profile bool.

BREAKING: -P now requires an address argument.
2026-05-07 07:06:54 +00:00
ns
40e66943cc
security: refuse to dial non-public addresses in LookupPort
The /port/ endpoint dialed whatever IP the request resolved to,
which combined with trusted X-Forwarded-For made the service an
SSRF / port-scan primitive against loopback, RFC1918, link-local,
and cloud metadata addresses.

LookupPort now refuses invalid, loopback, private, link-local
unicast/multicast, unspecified, and multicast addresses.
2026-05-07 07:06:54 +00:00
ns
5b9bddabfa
dockerfile update 2026-02-16 09:21:31 +00:00
ns
d4ea344954
gha update 2026-02-16 09:20:21 +00:00
ns
c9a867a649
Merge remote-tracking branch 'origin/dependabot/github_actions/actions/setup-go-6' 2026-02-16 09:18:41 +00:00
ns
05b1d9842c
Merge remote-tracking branch 'origin/dependabot/github_actions/actions/checkout-6' 2026-02-16 09:18:35 +00:00
ns
88c947bbf7
Merge remote-tracking branch 'origin/dependabot/github_actions/actions/upload-artifact-6' 2026-02-16 09:18:27 +00:00
ns
1d13630914
dockerfile update 2026-02-16 09:14:43 +00:00
ns
ddedb365a6
go.mod update 2026-02-16 09:11:55 +00:00
dependabot[bot]
d04ce4802f
build(deps): bump actions/upload-artifact from 5 to 6
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-15 06:12:07 +00:00
dependabot[bot]
299d63b57a
build(deps): bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-24 06:18:59 +00:00
ns
c40dc1b5c3
fix metrocode 2025-11-15 12:58:26 +00:00
ns
648d34e1ef
ci 2025-11-15 12:54:31 +00:00
ns
dccbdd19a1
git hygiene 2025-11-15 12:51:15 +00:00
ns
fbdcc41337
io/ioutil 2025-11-15 12:47:54 +00:00
ns
cb228ef7e1
geoip2-golang/v2 2025-11-15 12:46:07 +00:00
dependabot[bot]
77144c142b
build(deps): bump actions/setup-go from 5 to 6
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 5 to 6.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-08 06:17:58 +00:00
ns
75be0a18ce
ci 2024-12-22 06:28:25 +00:00
ns
72f226547c
go 1.23 2024-12-22 06:27:35 +00:00
N.S.
245c7520e4
Merge pull request #1 from thecodingrobot/dependabot/github_actions/actions/setup-go-5
build(deps): bump actions/setup-go from 2 to 5
2024-12-22 08:26:01 +02:00
N.S.
69c2ce2a33
Merge pull request #2 from thecodingrobot/dependabot/github_actions/actions/checkout-4
build(deps): bump actions/checkout from 2 to 4
2024-12-22 08:25:43 +02:00
N.S.
d401e380a3
Merge pull request #3 from thecodingrobot/dependabot/go_modules/github.com/oschwald/geoip2-golang-1.11.0
build(deps): bump github.com/oschwald/geoip2-golang from 1.5.0 to 1.11.0
2024-12-22 08:25:33 +02:00
dependabot[bot]
8a3a6289ee
build(deps): bump github.com/oschwald/geoip2-golang from 1.5.0 to 1.11.0
Bumps [github.com/oschwald/geoip2-golang](https://github.com/oschwald/geoip2-golang) from 1.5.0 to 1.11.0.
- [Release notes](https://github.com/oschwald/geoip2-golang/releases)
- [Commits](https://github.com/oschwald/geoip2-golang/compare/v1.5.0...v1.11.0)

---
updated-dependencies:
- dependency-name: github.com/oschwald/geoip2-golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-22 06:24:42 +00:00
dependabot[bot]
220b5f5e3c
build(deps): bump actions/checkout from 2 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-22 06:24:37 +00:00
dependabot[bot]
86aa5604f1
build(deps): bump actions/setup-go from 2 to 5
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-22 06:24:34 +00:00
ns
2351c58d72
dependabot 2024-12-22 06:23:28 +00:00
Jegor van Opdorp
076c96b814
Merge pull request #7 from leafcloudhq/add-data-dir-copy
added copy data dir
2024-09-12 11:57:16 +02:00
Jegor van Opdorp
cf3dcb2a4c added copy data dir 2024-09-12 11:54:13 +02:00
Jegor van Opdorp
435f0c1657
Merge pull request #6 from leafcloudhq/fix-geoip-download
added geoip-download to docker-pushx and made GEOIP_LICENSE_KEY option
2024-09-12 11:33:56 +02:00
Jegor van Opdorp
a2080e793a added geoip-download to docker-pushx and made GEOIP_LICENSE_KEY option 2024-09-12 11:28:28 +02:00
Jegor van Opdorp
16fe6dde10
Merge pull request #5 from leafcloudhq/fix-pipeline
updated makefile to use https git
2024-09-12 10:01:12 +02:00
Jegor van Opdorp
09ca19cee0 updated makefile to use https git 2024-09-12 09:58:49 +02:00
Jegor van Opdorp
a21e73a1b7
Merge branch 'mpolden:master' into master 2024-09-12 09:37:32 +02:00
Jegor van Opdorp
a7e88fb5ee
Merge pull request #3 from WhyAydan/master
Updated GeoDB
2024-09-12 09:35:42 +02:00
Aydan Abrahams
26e73a85a4
Updated GeoDB 2024-08-16 08:31:15 +01:00
Martin Polden
d84665c26c
Merge pull request #162 from Alphakilo/master
Implement `/asn-org` endpoint
2023-05-21 20:26:14 +02:00
Martin Polden
31b161feee
Merge pull request #145 from ashleyprimo/master
Update README -> MaxMind Geo Information
2023-05-21 20:25:51 +02:00
Martin Polden
b2859dc565
Merge pull request #125 from marcellmartini/master
Refactory of multiValueFlag.String()
2023-05-21 20:25:25 +02:00
Jegor van Opdorp
44107a913d
Merge pull request #2 from mpolden/master
sync upstream
2023-03-09 14:07:28 +01:00
Jegor van Opdorp
e52e98d27f updated repo 2023-03-09 14:04:19 +01:00
Alphakilo
44ce088bb3 update docs 2022-09-04 00:09:52 +02:00