Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
I was used to see the initialization of services just on a main.go file, with all of the initialization of the structs or functions that are needed for the system to start. However, I've been seeing a bunch of projects (including some at my company) that have started to use Cobra for creating these services, and I don't mean a CLI application, but stuff like a REST or gRPC server, or kafka consumers/producers.
Kubernetes itself is a good example. They aren’t using Cobra, but each of the cluster components (kube-apiserver, kube-proxy , etc.) have a CLI entrypoint. While probably overkill for smaller projects, I’ve seen this on larger projects once the number of arguments and flags grows beyond what you’d want to deal with on your own in a main function. For example, just look at the number of arguments to the kube-apiserver.
Here's a library that I use to create system services: https://github.com/kardianos/service