Design Philosophy
This template makes deliberate architectural choices to optimize for:- Resilience: Exponential backoff, bounded concurrency, and graceful error handling
- Observability: Structured logging with context injection throughout
- State Management: File-backed persistence and database transactions
- HTTP Excellence: TLS fingerprinting, cookie management, and proxy support
- Developer Experience: Hot reload, type-safe queries, and clear separation of concerns
Core Architecture
The template follows a layered architecture that separates concerns while maintaining simplicity:Entry Point
The application starts incmd/template/main.go, which demonstrates the recommended initialization pattern:
cmd/template/main.go
- Graceful shutdown on SIGINT/SIGTERM
- Clear error reporting with context
- Environment validation before execution
Domain Layer
Thepkg/template package demonstrates how to compose HTTP clients and database connections:
pkg/template/template.go
Replace
pkg/template with your own domain logic. This is a skeleton service meant to be customized.Key Capabilities
TLS Fingerprinting
Thepkg/client package provides an HTTP client with browser-accurate TLS and HTTP/2 fingerprinting:
Bounded Concurrency
Thepkg/worker package wraps errgroup to provide safe, bounded parallelism:
pkg/worker/worker.go
Retry Logic
Thepkg/retry package implements exponential backoff with full jitter:
State Persistence
Thepkg/state package provides type-safe, file-backed state with cross-platform locking:
When to Use This Template
This template is ideal for:Web Scrapers
TLS fingerprinting, cookie management, and retry logic built-in
API Bots
Structured logging, state persistence, and bounded concurrency
Data Collectors
PostgreSQL integration with type-safe queries via sqlc
Background Services
Graceful shutdown, signal handling, and context propagation
Not Recommended For
This template may be overkill for:- Simple HTTP servers (use
net/httpdirectly) - Serverless functions (too much initialization overhead)
- CLI tools without network I/O (use
cobraorflaginstead)
Opinionated Choices
Why These Defaults?
-
TLS Verification Disabled by Default: Scrapers often need to bypass SSL verification for proxies or testing. Re-enable in production with
client.WithInsecureSkipVerify(false). - Keep-Alives Disabled: Prevents connection pool exhaustion when scraping many domains. Enable for API clients hitting the same endpoint.
-
Structured Logging:
slogwithtintprovides human-readable development logs that can be switched to JSON in production. -
Single Binary: The
cmd/directory follows the standard Go project layout, making it easy to add multiple binaries later. - PostgreSQL Over SQLite: Production scrapers need concurrent writes and better locking. Postgres is opt-in—comment it out if not needed.
Multi-Stage Docker
The Dockerfile provides three build targets:Next Steps
Project Structure
Understand the directory layout and where to add your code
Configuration
Learn how to configure environment variables and add new settings
