...

/

Adding Finishing Touches to the Initial Client for the REST API

Adding Finishing Touches to the Initial Client for the REST API

Develop the client-side of the REST API.

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:

Press + to interact
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 configuration values.
import (
"fmt"
"io"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Importing the required list

Then we edit the command ...