The Go Template follows the Standard Go Project Layout with some opinionated additions. Every directory serves a specific purpose to keep your codebase organized as it grows.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/aarock1234/go-template/llms.txt
Use this file to discover all available pages before exploring further.
Directory Overview
cmd/ - Entry Points
Thecmd/ directory contains executable entry points. Each subdirectory becomes a binary.
cmd/template/
The main application entry point that wires together your services:cmd/template/main.go
- Signal handling for graceful shutdown
- Configuration loading and validation
- Service initialization and dependency injection
- Top-level error handling
Rename
cmd/template/ to match your project name (e.g., cmd/scraper/). Update the binary name in the Makefile accordingly.cmd/setup/
An interactive setup wizard that runs after cloning:- Remove unused features (PostgreSQL, Docker, etc.)
- Clean up template files
- Configure your development environment
pkg/ - Library Code
Thepkg/ directory contains reusable packages that can be imported by your application or other projects.
pkg/template/ - Domain Logic (Replace This)
This is a skeleton service demonstrating how to wire dependencies. Replace it with your actual business logic:pkg/template/template.go
- Scraper logic (fetch, parse, store)
- Bot workflows (authenticate, execute tasks)
- Service orchestration (coordinate multiple APIs)
pkg/client/ - HTTP Client
A production-ready HTTP client with advanced features:TLS Fingerprinting
TLS Fingerprinting
Mimic browser TLS handshakes to avoid detection:Uses
refraction-networking/utls to replicate Chrome, Firefox, Safari, and Edge fingerprints.Cookie Management
Cookie Management
Proxy Support
Proxy Support
HTTP/HTTPS/SOCKS5 proxy with authentication:
Redirect Handling
Redirect Handling
Follows redirects while preserving cookies:
pkg/db/ - Database Layer
PostgreSQL integration with type-safe queries using sqlc:pkg/db/db.go
- Connection pooling via
pgxpool - Transaction helpers (
InTx,Begin) - Advisory locks for distributed coordination
- Type-safe queries generated from SQL
pkg/env/ - Configuration
Loads environment variables from.env files with struct-tag validation:
pkg/env/config.go
- Reads from
.envfile if present - Process environment variables take precedence
- Validates required fields at startup
- Supports quoted values and comments
pkg/log/ - Structured Logging
Configuresslog with colorized output and context injection:
pkg/log/log.go
- Colorized output in terminals (via
tint) - Context-aware logging with request IDs
- Configurable log levels via
LOG_LEVELenv var - Automatic Windows color support
pkg/retry/ - Exponential Backoff
Retry failed operations with exponential backoff and jitter:pkg/retry/retry.go
pkg/worker/ - Bounded Concurrency
Generic worker pool built onerrgroup:
pkg/worker/worker.go
- Bounded parallelism (prevents overwhelming targets)
- Fail-fast: First error cancels remaining work
- Generic: Works with any slice type
Mapvariant returns results in order
pkg/state/ - File-Based State
Persist application state across restarts with file locking:pkg/state/state.go
- Remember the last processed item
- Track completion across restarts
- Implement resumable workflows
pkg/cycle/ - Round-Robin Rotator
Thread-safe round-robin rotation (useful for proxies, user agents, etc.):pkg/ptr/ - Pointer Helpers
Generic utilities for working with pointers:Root Files
Dockerfile
Multi-stage build with three targets:compose.yaml
Local development stack with hot reload:Makefile
Common development tasks:| Command | Description |
|---|---|
make dev | Run locally with go run |
make build | Compile binary to bin/template |
make test | Run tests with race detector |
make generate | Generate sqlc code |
make db | Start PostgreSQL only |
make migrate | Run database migrations |
Adding New Packages
When adding functionality, follow these guidelines:Choose the Right Location
- Domain logic:
pkg/yourservice/ - Infrastructure: Extend existing
pkg/packages - New utility: Create new
pkg/utility/
Keep It Focused
Each package should have a single, clear responsibility. If a file exceeds 500 lines, consider splitting it.
Next Steps
Configuration
Learn how to manage environment variables and settings
Architecture
Understand the design philosophy and patterns
