In this lesson, I take a detour from the planned integration testing to implement an auto-registration system for LLM providers, inspired by how database drivers work in Go. The idea is to create a system where providers automatically register themselves when imported, similar to how you import `lib/pq` for PostgreSQL. I implement this by creating a provider interface with a `GenerateCommitMessage` method, a registry map to store providers, and registration functions that providers call in their `init()` methods.
The implementation involves converting our existing ChatGPT and Ollama implementations to use this new pattern, where each provider registers itself with a name during package initialization. In the commit command, we replace the switch statement with a simple provider lookup by name. The magic happens through blank imports (`_ "internal/llm/chatgpt"`), which trigger the init functions and auto-register the providers. Testing confirms it works—the providers are now dynamically discovered and selectable via the `--provider` flag, making it trivial to add new LLM providers in the future without modifying the core command logic.