Search⌘ K
AI Features

Adding Finishing Touches to the Initial Client for the REST API

Explore how to add the list command to a Go CLI client for a REST API. Learn to use the Cobra generator for command setup, leverage Viper for configuration, and employ the tabwriter package for formatted output. Understand how to fetch and display to-do items efficiently within your Go application.

Now we can use these functions to implement the first command list to list all to-do items from the API. We use the Cobra generator to add the list command to our application:

Shell
cobra add list

Updating the cmd/list.go file

We edit the file cmd/list.go and update the import section to include the following packages:

  • io to use the io.Writer interface for flexible output.
  • os to use the os.Stdout for output.
  • text/tabwriter to print formatted tabulated data.
  • github.com/spf13/viper to obtain
...