$ show mailgun/holster
Holster is a Go utility library collection providing building blocks for distributed systems. It offers deterministic time control for testing, leader election implementations (etcd-based and Raft-inspired), enhanced error handling with context and stack traces, service discovery (Consul, DNS SRV), OpenTelemetry tracing, caching mechanisms (LRU, TTL, ExpireCache), retry utilities, HTTP request signing, gRPC connection pooling, and MX record resolution. Designed as drop-in replacements for standard library components with enhanced functionality, it focuses on solving common infrastructure challenges in microservices architectures. The library maintains a clear separation of concerns with each package addressing a specific cross-cutting concern.
The LLM identified 5 files worth highlighting for reuse:
Provides a mockable time interface for deterministic testing. Allows freezing time, advancing time, and scheduling timed functions. Self-contained with minimal dependencies (only time and context), demonstrating the pattern of injecting time-dependent behavior for testability.
Enhances standard error handling with context, stack traces, and causer interface. Provides Wrap, WithContext, and WithStack functions to add contextual information to errors while preserving the original error. Demonstrates non-obvious skill in error chain management and is designed as a drop-in replacement for standard error handling.
Implements an extended WaitGroup that collects errors from goroutines. Solves the common pattern of waiting for multiple concurrent operations that may fail, returning the first error or a composite error. Self-contained and reusable in any concurrent Go program.
Implements a thread-safe LRU cache with optional TTL and statistics tracking. Uses a doubly linked list and map for O(1) operations. Demonstrates careful concurrency control with mutexes and provides cache hit/miss metrics. Self-contained data structure suitable for general use.
Provides HTTP request signing and verification using HMAC-SHA256 with nonce and timestamp to prevent replay attacks. Includes nonce cache for replay protection. Self-contained and depends only on standard crypto/hmac and time packages, making it easily extractable for securing HTTP APIs.