Creating a client for the statistics service
In this subsection, we create a command line utility that interacts with the statistics web service that was developed earlier in this chapter. This version of the statistics client is going to be created using the cobra
package, and as expected, it is going to go under ~/go/src
: ~/go/src/github.com/mactsouk/mGo4th/ch09/client
. The previous directory contains the final version of the client. The initial steps for creating the client are the following:
$ cd ~/go/src/github.com/mactsouk/mGo4th/ch09/client
$ go mod init
$ ~/go/bin/cobra init
$ ~/go/bin/cobra add search
$ ~/go/bin/cobra add insert
$ ~/go/bin/cobra add delete
$ ~/go/bin/cobra add status
$ ~/go/bin/cobra add list
So, we have a command line utility with five commands, named search
, insert
, delete
, status
, and list
. After that, we need to implement the commands and define their local parameters in order to interact with the statistics server.
Now, let us see the implementations...