Skip to content

refactor: cleanup pass — sqlc, slog, scraper registry, drop go-jet - #7

Merged
ArnabXD merged 10 commits into
mainfrom
refactor/ponytail-cleanup
Jun 23, 2026
Merged

refactor: cleanup pass — sqlc, slog, scraper registry, drop go-jet#7
ArnabXD merged 10 commits into
mainfrom
refactor/ponytail-cleanup

Conversation

@ArnabXD

@ArnabXD ArnabXD commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Cleanup pass over the codebase: delete dead code, swap hand-rolled bits for stdlib/generated equivalents, drop one runtime dependency, and remove config duplication. No behaviour changes — same config, same API responses, same DB schema.

What changed

  • Dropped go-jet for sqlc. Queries live in query.sql; the type-safe layer is generated into internal/database/db/. One query (GetProxiesByAddresses) stays hand-written because sqlc's sqlite engine doesn't support sqlc.slice() IN-lists.
  • Logging is now slog end to end. The custom logger is a thin facade over log/slog; main.go and config.go (the last stdlib-log holdouts) now go through it too, so startup logs match the rest. Added logger.Fatal (log-then-exit). Level via LOG_LEVEL.
  • API responses use encoding/json instead of hand-built fmt.Fprintf — also fixes a real bug where country/type values with quotes or backslashes produced invalid JSON.
  • Scrapers collapsed into a registry. Five near-identical per-source files became one sources slice + a shared line parser. Adding a text-list source is one struct entry.
  • Dropped geonode — its JSON API is broken and the only unique field (country) is cosmetic. Removed from defaults, validator, and the example config.
  • Config duplication removed. main.go used to hand-copy cfg into three near-identical structs and NewDBManager took 7 positional args. Packages now consume the internal/config sections directly; NewDBManager(db, cfg). Deleted the duplicate structs and proxy.DefaultConfig.
  • Constructor naming. Dropped the now-redundant WithConfig suffix (the no-config variants were deleted), so they're the idiomatic NewT.
  • Deleted dead code: legacy Manager and its single-impl interface, unused helpers, no-config constructors.

Notes

  • schema.sql (read by sqlc) and initSchema() in db.go are now two copies of the schema and must stay in sync — flagged in CLAUDE.md. Can unify via go:embed in a follow-up.
  • Stayed on modernc.org/sqlite (pure-Go) on purpose: keeps the static build and tiny Docker image, and DB writes aren't on the hot path.
  • pkg/* now imports internal/config. Fine for a single-binary app; if a package is ever extracted as a library it'd take a small local config struct again.

Net ~−1900 source lines across the branch. Build, vet, and tests green.

ArnabXD added 10 commits June 23, 2026 22:38
… constructors)

- Remove legacy manager.Manager + single-impl ProxyManager interface
- Server uses *manager.DBManager directly, drop type-asserts
- Delete unused checker helpers (setters, GetHealthyCount, GroupByStatus, TestSingleProxy)
- Delete dead no-config scraper/checker constructors

~400 net lines removed, no behavior change.
- Rewrite internal/logger as a thin facade over log/slog: real JSON
  output, levels via LOG_LEVEL, same call-site API (no churn).
- Replace hand-rolled fmt.Fprintf JSON in /stats and /proxies with
  encoding/json. Fixes a real bug: unescaped quotes/backslashes in
  proxy country/type produced invalid JSON. Deletes formatMap.
- Drop a redundant per-batch log.Printf in service.go.
Scraper:
- 5 near-identical scraper files -> one generic list.go driven by a
  source registry (URL list + default type). parseLine handles both
  proto://host:port and bare host:port. Add list_test.go for the parser.
- Drop geonode entirely: its JSON API returns errors and its only unique
  data (Country) is cosmetic. Removes the lone JSON scraper. Update the
  config validator oneof + default sources accordingly.

Checker:
- testProxy/testSOCKS4Proxy/testSOCKS5Proxy were ~90% identical; split
  into buildTransport + runCheck. Name the SOCKS4-via-SOCKS5 limitation
  honestly in a comment instead of silently mislabeling it.
- db_checker: extract dbProxyToResult, killing a duplicated status switch
  across getCachedResults/getAllResults.
- Add compile-time asserts that checker/database ProxyStatus stay in sync.
- Add sqlc.yaml + schema.sql + query.sql; generate typed query layer
  into internal/database/db (sqlc v1.31.1).
- Rewrite service.go as thin wrappers over generated queries. The only
  hand-written SQL left is GetProxiesByAddresses (sqlc's sqlite engine
  doesn't support sqlc.slice() for IN lists).
- BatchUpdateProxyHealth now uses Queries.WithTx + generated
  MarkProxyHealthy/MarkProxyUnhealthy instead of hand-prepared stmts.
- db_checker uses database.Proxy (re-exported sqlc model) in place of
  go-jet's model.Proxies; ID is now a non-pointer int64.
- Delete internal/database/models (go-jet codegen); go mod tidy drops
  github.com/go-jet/jet/v2 entirely.
- Drop unused GetProxiesNeedingCheck.

Verified end-to-end against a real SQLite DB (upsert, batch health
update, IN lookup, healthy filter, stats).
… geonode)

- Database section: go-jet -> sqlc; document schema.sql/query.sql,
  the service.go wrappers, and the schema-in-two-places caveat.
- Scraper section: switch-based source registration -> sources registry
  in list.go; drop geonode (its JSON API is dead).
- Logging: reflect log/slog (component/id fields, LOG_LEVEL).
- Dependencies: drop go-jet, note sqlc is build-time only.
The no-config constructor variants were deleted earlier this session, so
WithConfig no longer disambiguates anything. Rename to the idiomatic NewT.
…ucts

main.go hand-copied cfg into three near-identical structs (proxy.Config,
checker.CheckerConfig, scraper.ScraperConfig) and NewDBManager took 7
positional args. The pkg/* structs were just renamed subsets of the
config.* sections.

Packages now take the config.* struct they need. Deletes the three
duplicate structs, proxy.DefaultConfig (setDefaults already covers it),
and ~30 lines of field copying. NewDBManager(db, cfg) replaces the
7-arg call.
main.go and config.go were the last stdlib-log holdouts, so startup logs
came out in a different format from everything else. Added logger.Fatal
(log-then-exit, mirroring log.Fatalf) and switched both files to the
component logger. PrintConfig's 7 lines collapse into one structured line.
Banner/version stay on fmt.Print (terminal output, not logs).
Stale source left over from the geonode removal — config validation now
rejects it, breaking a fresh copy of the example config.
Version was hardcoded to 1.0.0 and never injected, so release binaries
printed the wrong version. Now set via -ldflags -X main.Version from the
git ref; default 'dev' for local builds. Dropped the hardcoded 'v' prefix
from the three print sites so the tag (v1.1.0) owns it (no more 'vv1.1.0').

CI built with Go 1.21 while go.mod requires 1.24.1 — bumped setup-go to
1.24 so release builds match.
@ArnabXD
ArnabXD merged commit bc54599 into main Jun 23, 2026
9 checks passed
@ArnabXD
ArnabXD deleted the refactor/ponytail-cleanup branch June 23, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant