goderive is a code generation tool for Go that automatically derives and generates boilerplate functions developers would otherwise need to write and maintain manually. The tool works by parsing Go source code to identify unimplemented functions with specific prefixes, then generates their implementations based on the input parameter types. When types are modified, goderive can regenerate these functions to keep them synchronized with the latest changes, solving the common problem of developers forgetting to update derived functions after adding fields to structs.
The repository provides an extensive collection of derivable functions organized into several categories. Recursive functions include Equal for comparing values, Compare for ordering, DeepCopy for duplicating data structures, Clone for creating copies, GoString for string representation, and Hash for computing hash values. Set-related functions encompass Keys for extracting map keys, Sort for ordering slices, Unique for removing duplicates, Set for converting slices to maps, Min and Max for finding extremes, Contains for membership testing, and Intersect and Union for set operations. Functional programming functions include Fmap for mapping operations, Join for flattening nested structures, Flip for argument reordering, Curry and Uncurry for function transformation, Tuple for creating tuple functions, Compose for function composition, Mem for memoization, Traverse for sequential operations, ToError for error conversion, and Apply for partial application. Concurrency-focused functions support channel operations including Fmap over channels, Join for channel flattening, Pipeline for channel composition, Do for concurrent operations, and Dup for channel duplication.
The tool uses a straightforward naming convention where functions are prefixed with derive followed by the function name in camel case, such as deriveEqual. Developers can derive multiple variants for different types by appending type-specific suffixes, allowing deriveEqualMyStruct and deriveEqualMySecondStruct to coexist. The command-line interface supports customizable function prefixes through flags, and features like autoname and dedup can automatically manage function naming to ensure uniqueness and prevent duplicate generation.
Installation is simple through go install, and goderive integrates seamlessly with Go's build ecosystem. It can be invoked directly from the command line using standard Go path semantics like goderive ./..., or integrated into build processes via go generate directives. The repository includes examples demonstrating various use cases and configuration approaches, from basic usage to custom prefix setups.
Several functions are marked as deprecated in favor of Go's native generics support, reflecting the tool's evolution as the language has matured. This indicates active maintenance and adaptation to modern Go practices. The tool addresses a genuine pain point in Go development where many common operations require repetitive, type-specific implementations that are tedious to maintain across evolving codebases.