Automatic cobra command registration with fx
Cobra is a popular Go package for creating CLIs. It provides a lot of functionality for creating commands, subcommands, and flags. However, it can be tedious to manually register all of your commands. fx is a Go package that provides a dependency injection framework. It can be used to automatically register your application components, including…
Dependency injection in go using fx, and replacing services for test
I’m writing a new go application and ended up giving fx (by uber) a try for dependency injection. The getting started docs were brilliant for my use case (creating an API), but the examples for how to inject mock services for tests were lacking, so I decided to write some code examples of how I…