$ show seborama/govcr
govcr is a Go library that records and replays HTTP/HTTPS interactions for testing purposes, acting as an HTTP mock. It wraps an http.Client to intercept requests, either playing back recorded responses from cassette files (JSON) or making live requests and recording them. The library supports various modes (normal, live-only, offline, read-only), cassette encryption (AES-GCM, ChaCha20Poly1305), multiple storage backends (local filesystem, AWS S3), flexible request matching, and request/response transformation via mutators. The architecture centers around a custom http.RoundTripper implementation that integrates cassette storage, request matching, mutation systems, and encryption layers.
The LLM identified 3 files worth highlighting for reuse:
Implements a flexible HTTP request matching system with support for both strict (method, URL, headers, body, trailer) and relaxed (method, URL only) matching. Demonstrates clean interface design through the RequestMatcher function type and composable RequestMatchers slice. Notable for its correct handling of multi-value headers using a postal sorting algorithm to compare unordered slices without order dependency. The package is highly cohesive, loosely coupled, and could be extracted as a standalone HTTP matching utility for any Go project needing request comparison logic.
Provides a powerful system for transforming HTTP requests and responses at recording or playback time using predicate-based conditional mutation. Features a clean separation between recording and replaying mutations, with rich built-in mutators for header manipulation, body transformation, and more. Demonstrates advanced functional programming concepts in Go through composable predicates (Any, All, Not, None) and clean separation of concerns. The mutation system is highly reusable as a standalone data transformation pipeline applicable beyond HTTP contexts.
Implements a clean storage abstraction layer for cassette persistence with well-defined FileIO interface supporting multiple backends (local filesystem, AWS S3). Shows excellent separation of concerns where encryption, compression, and core cassette logic are implemented as composable filters. The design follows dependency inversion principles, making it easy to add new storage backends without modifying core logic. Notable for its elegant handling of encryption/decryption as transparent filters and proper error propagation through the storage layer.