fix: address code review issues on PR #10 (HAN-384)

- runner.go: store fingerprints in local var, call formatter.SetFingerprints()
  instead of mutating caller's *Config; removes Fingerprints field from Config
- fingerprint.go: use singleflight.Group in Query to coalesce concurrent
  probes for the same IP, eliminating the double-probe race
- output layer: add SetFingerprints(map[string]string) to Formatter interface;
  textFormatter and jsonFormatter each hold their own fingerprints field
- formatter_test.go: add TestTextFormatterWriteSummaryShowsVersions and
  TestJSONFormatterWriteSummaryShowsVersions verifying version output

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
Gary Hansen
2026-06-08 02:59:38 +10:00
co-authored by Copilot multica-agent
parent 3e7580b919
commit c96d18859f
7 changed files with 113 additions and 20 deletions
+10 -5
View File
@@ -9,9 +9,10 @@ import (
)
type jsonFormatter struct {
cfg *Config
w io.Writer
payload jsonDocument
cfg *Config
w io.Writer
payload jsonDocument
fingerprints map[string]string
}
type jsonDocument struct {
@@ -71,6 +72,10 @@ func newJSONFormatter(cfg *Config, w io.Writer) *jsonFormatter {
}
}
func (f *jsonFormatter) SetFingerprints(fps map[string]string) {
f.fingerprints = fps
}
func (f *jsonFormatter) WriteProgress(event traverse.TraversalEvent) error {
if !f.cfg.ShowProgress {
return nil
@@ -106,9 +111,9 @@ func (f *jsonFormatter) WriteSummary(results []traverse.TraversalResult) error {
servers := collectServers(results)
for name, ips := range servers {
srv := jsonServer{Name: name, IPs: ips}
if f.cfg.ShowVersions && f.cfg.Fingerprints != nil {
if f.cfg.ShowVersions && f.fingerprints != nil {
for _, ip := range ips {
if v := f.cfg.Fingerprints[ip]; v != "" {
if v := f.fingerprints[ip]; v != "" {
srv.Version = v
break
}