Skip to content

Rewrite SilkRouter as a dependency-free, cross-platform Go binary#1

Draft
serainox420 wants to merge 1 commit into
mainfrom
claude/golang-proxy-caching-rewrite-xaduwc
Draft

Rewrite SilkRouter as a dependency-free, cross-platform Go binary#1
serainox420 wants to merge 1 commit into
mainfrom
claude/golang-proxy-caching-rewrite-xaduwc

Conversation

@serainox420

Copy link
Copy Markdown
Contributor

Summary

Full rewrite of the SilkRouter bash toolkit (px.sh, blcheck.sh, proxycheck.sh) into a single, dependency-free, cross-platform Go binary. Built with CGO_ENABLED=0 and the standard library only (no go.sum, no external modules), it cross-compiles to Linux, Windows and macOS on amd64/arm64 and needs no curl/awk/shuf at runtime.

All three scripts' logic is combined into one subcommand-driven executable, structured for easy future extension.

What's included

Native proxy dialers for every protocolhttp, https, socks4, socks4a, socks5 — hand-rolled over the standard library (internal/proxy). SOCKS4/4a are implemented from scratch since Go's x/net/proxy doesn't cover them. Unified Dial/Transport handling so adding a protocol means one switch arm + a handshake.

More ways to cache a proxy than Cloudflare — validation is now a pluggable probe registry (internal/probe) with nine built-ins: cloudflare (default), google, gstatic, msft, apple, example, ipify, aws, icanhazip — plus -test-url for a custom endpoint. Adding a new probe is a one-line register(...).

Error handling across the whole flow — every dial, handshake, fetch and probe returns a descriptive error; the cache builder reports precise per-proxy failure reasons and refuses to overwrite a good cache with an empty result.

Offline capability — the consolidated proxy list is embedded via go:embed (-builtin).

Subcommands: build, recache, list, route, check, blcheck, proxycheck, probes, version. Cache file format stays compatible with the old tool.

Layout

main.go / cmd_*.go   CLI dispatch + flag parsing
internal/proxy       Proxy type, parsing, dialers/transport
internal/probe       caching probes (registry)
internal/source      candidate lists (url / file / embedded)
internal/cache       concurrent build (worker pool), merge, load, save, report
internal/router      proxy selection + command execution
internal/scan        blcheck + proxycheck HTML scrapers
internal/ui          cross-platform colour handling
legacy/              original bash scripts, preserved

Testing

  • go test ./... — parser table tests, and integration tests that exercise all four dial paths (SOCKS5, SOCKS4, HTTP forward-GET, HTTP CONNECT) and the concurrent build pipeline against in-process mock proxy servers.
  • go vet ./... and gofmt clean.
  • Cross-compiled and verified static for linux/amd64, linux/arm64, windows/amd64, darwin/arm64 (ldd → "not a dynamic executable").
  • make check (fmt-check + vet + test) passes; race detector passes via make test-race.

Docs & tooling

  • New README.md documenting every subcommand, flag, probe and the package layout.
  • New Makefile: build, install, run, test, test-race, check, release (cross-compile matrix), update, clean.

🤖 Generated with Claude Code


Generated by Claude Code

Port the bash toolkit (px.sh, blcheck.sh, proxycheck.sh) into one static,
cross-platform Go binary (Linux/Windows/macOS, amd64/arm64) built with
CGO_ENABLED=0 and the standard library only — no go.sum, no runtime deps.

Highlights
- Native dialers for http, https, socks4, socks4a and socks5, hand-rolled
  over the standard library (incl. SOCKS4/4a, which x/net/proxy lacks).
- Pluggable caching probes: nine built-ins (cloudflare, google, gstatic,
  msft, apple, example, ipify, aws, icanhazip) plus custom -test-url, so
  validation is no longer hard-wired to Cloudflare. Adding one is a
  one-line registry entry.
- Descriptive error handling across dialing, handshakes, fetching, probing
  and cache building; the builder never overwrites a good cache with an
  empty result.
- Consolidated proxy list embedded via go:embed for offline builds
  (-builtin).
- Subcommands: build, recache, list, route, check, blcheck, proxycheck,
  probes, version.

Layout
- internal/proxy  Proxy type, parsing, dialers/transport
- internal/probe  caching probes (registry)
- internal/source candidate lists (url/file/embedded)
- internal/cache  concurrent build, merge, load, save, report
- internal/router proxy selection + command execution
- internal/scan   blcheck + proxycheck HTML scrapers
- internal/ui     cross-platform colour handling

Tests cover the parser and exercise all four dial paths and the concurrent
build pipeline against in-process mock proxy servers.

Original shell scripts preserved under legacy/. New README.md and Makefile
(build/install/test/release/update) added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M4KGZH66trVJ6CiEZUGrxt
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.

2 participants