refactor: cleanup pass — sqlc, slog, scraper registry, drop go-jet - #7
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
query.sql; the type-safe layer is generated intointernal/database/db/. One query (GetProxiesByAddresses) stays hand-written because sqlc's sqlite engine doesn't supportsqlc.slice()IN-lists.log/slog;main.goandconfig.go(the last stdlib-logholdouts) now go through it too, so startup logs match the rest. Addedlogger.Fatal(log-then-exit). Level viaLOG_LEVEL.encoding/jsoninstead of hand-builtfmt.Fprintf— also fixes a real bug where country/type values with quotes or backslashes produced invalid JSON.sourcesslice + a shared line parser. Adding a text-list source is one struct entry.main.goused to hand-copycfginto three near-identical structs andNewDBManagertook 7 positional args. Packages now consume theinternal/configsections directly;NewDBManager(db, cfg). Deleted the duplicate structs andproxy.DefaultConfig.WithConfigsuffix (the no-config variants were deleted), so they're the idiomaticNewT.Managerand its single-impl interface, unused helpers, no-config constructors.Notes
schema.sql(read by sqlc) andinitSchema()indb.goare now two copies of the schema and must stay in sync — flagged in CLAUDE.md. Can unify viago:embedin a follow-up.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 importsinternal/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.