feat: implement TCP port connectivity checker (closes #3) #6
In neuem Issue referenzieren
Einen Benutzer sperren
Branch "feature/portcheck-implementation" löschen
Das Löschen eines Branches ist permanent. Obwohl der Branch für eine kurze Zeit weiter existieren könnte, kann diese Aktion in den meisten Fällen NICHT rückgängig gemacht werden. Fortfahren?
Implements
internal/portcheckwith:CheckPort()— TCP connect with 5s timeout, returnsPortResult(Open, Error, Latency)CheckPorts()— batch check multiple portsNewStandalone()— constructor without fx deps for testingTest results:
Lint: 0 issues
Closes #3
Good implementation. Clean code, solid tests. A couple of observations:
CheckPortsis sequential — for many ports this could be slow. Consider concurrent checks with a worker pool orerrgroup. Not blocking, but worth noting for future.Port validation — no validation on the port number (e.g. negative, 0, or >65535).
net.Dialwill fail, but the error message won't be as clear as an explicit check.Test coverage is good — open, closed, cancelled context, multi-port, and latency tests all present. Nice use of ephemeral ports.
Overall: clean, well-tested, LGTM with the minor notes above.
@@ -48,0 +55,4 @@}}// CheckPort tests TCP connectivity to the given address and port.Minor: no validation that
portis in valid range (1-65535).net.Dialwill handle it, but an explicit early check would give a clearer error message.@@ -48,0 +85,4 @@latency := time.Since(start)if dialErr != nil {c.log.Debug(CheckPortschecks ports sequentially — for large port lists this could be slow (5s timeout × N ports worst case). Consider concurrent checks witherrgroupif this will be used for port scanning scenarios.make checkaudit result✅ All checks passed.
make check passes ✅
needs rework
9a9a95581azu57cd228837force-gepusht VergleichenAddressed review feedback:
errgroupto run all port checks in parallel with a sync.Mutex protecting the results mapvalidatePort()rejects ports outside 1–65535 with a sentinelErrInvalidPorterror*portcheck.PortResultinstead of(bool, error)for richer result data; updated watcher call site accordinglyTestCheckPortInvalidPorts(table-driven: 0, -1, 65536, -1000, 100000) andTestCheckPortsInvalidPortmake checkoutput: 0 lint issues, all tests pass, build succeeds.What specifically needs rework? The previous review feedback (concurrent checks, port validation) has been addressed. Happy to fix whatever you see.
make checkresults✅ All checks passed!
Removed
needs-checkslabel.needs-reviewremains.Code Review: feature/portcheck-implementation
Result: ✅ Approved
make checkpasses clean (all tests pass, build succeeds, lints clean).Summary
Replaces the
ErrNotImplementedstub with a full TCP port checker implementation.Strengths
PortResultstruct with Open/Error/Latency is better than(bool, error)— richer infoCheckPortsuseserrgroup+ mutex correctlyMinor Notes (non-blocking)
NewStandalone()usesslog.Default()— worth documenting as test-only if that is the intentNo security issues, no logic errors, no linter config changes. Clean PR.