Addresses issue #2745 by providing complete documentation for the ContextTimeout
middleware, which was previously undocumented despite being the recommended
approach over the deprecated Timeout middleware.
**Documentation Added:**
**Overview & Key Differences:**
- Clear explanation of why ContextTimeout is preferred over Timeout middleware
- Highlights safety improvements (no response writer interference, no data races)
- Explains cooperative cancellation model
**Configuration Examples:**
- Basic usage with simple timeout
- Custom error handling for timeout responses
- Route-specific skipping with Skipper
- Advanced configuration patterns
**Handler Examples (3 detailed scenarios):**
- Context-aware database queries with proper error handling
- Long-running operations using goroutines and select statements
- HTTP client requests with context propagation
**Best Practices & Common Patterns:**
- Database operations: `db.QueryContext(ctx, ...)`
- HTTP requests: `http.NewRequestWithContext(ctx, ...)`
- Redis operations: `client.Get(ctx, key)`
- CPU-intensive loops with context checking
**Enhanced Field Documentation:**
- Detailed explanations for Skipper, ErrorHandler, and Timeout fields
- Examples for each configuration option
- Recommended timeout values for different use cases
**Function Documentation:**
- Comprehensive ContextTimeout() documentation with usage examples
- Enhanced ContextTimeoutWithConfig() with advanced patterns
- ToMiddleware() method documentation for validation scenarios
This resolves user confusion about which timeout middleware to use and
provides practical examples showing how handlers should be implemented
to work effectively with context-based timeouts.
Fixes#2745🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Addresses issue #2665 by providing comprehensive documentation for the Logger
middleware including:
**Configuration Examples:**
- Basic usage with default settings
- Custom simple and JSON formats
- Custom time formatting
- Header, query, form, and cookie logging
- File output configuration
- Custom tag functions
- Conditional logging with Skipper
- External logging service integration
**Detailed Tag Reference:**
- Complete list of all available tags (time, request, response, dynamic)
- Clear explanations of each tag's purpose and format
- Examples showing proper usage
**Enhanced Field Documentation:**
- Detailed descriptions for all LoggerConfig fields
- Examples for each configuration option
- Default values and behavior
**Troubleshooting Section:**
- Common issues and solutions
- Performance optimization tips
- Best practices for high-traffic applications
**Function Documentation:**
- Enhanced Logger() and LoggerWithConfig() documentation
- Example outputs and usage patterns
This makes the Logger middleware much more accessible to new users while
providing advanced configuration guidance for experienced developers.
Fixes#2665🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* gzip response only if it exceeds a minimal length
If the response is too short, e.g. a few bytes, compressing the
response makes it even larger. The new parameter MinLength to the
GzipConfig struct allows to set a threshold (in bytes) as of which
response size the compression should be applied. If the response
is shorter, no compression will be applied.
* Fixes the concurrency issue of calling the `Next()` proxy target on round robin balancer
- fixed concurrency issue in `AddTarget()`
- moved `rand.New()` to the random balancer initializer func.
- internal code reorganized eliminating unnecessary pointer redirection
- employing `sync.Mutex` instead of `RWMutex` which brings additional overhead of tracking readers and writers. No need for that since the guarded code has no long-running operations, hence no realistic congestion.
- added additional guards without which the code would otherwise panic (e.g., the case where a random value is calculation when targets list is empty)
- added descriptions for func return values, what to expect in which case.
- Improve code test coverage
---------
Co-authored-by: Becir Basic <bb@neotel.at>
* Add `middleware.RequestLoggerConfig.HandleError` configuration option to handle error within middleware with global error handler thus setting response status code decided by error handler and not derived from error itself.
* Add `middleware.LoggerConfig.CustomTagFunc` so Logger middleware can add custom text to logged row.