March 2021
Intermediate to advanced
260 pages
5h 45m
English
Our agent CLI will provide just enough features to use as a Docker image’s entry point and run our service, parse flags, and then configure and run the agent.
I use the Cobra[57] library to handle commands and flags because it works well for creating both simple CLIs and complex applications. It’s used in the Go community by projects such as Kubernetes, Docker, Helm, Etcd, Hugo, and more. And Cobra integrates with a library called Viper,[58] which is a complete configuration solution for Go applications.
The first step is to create a cmd/proglog/main.go file, beginning with this code:
| | package main |
| | |
| | import ( |
| | "log" |
| | "os" |
| | "os/signal" |
| | "path" |
| | "syscall" ... |
Read now
Unlock full access