Implementing application I/O
CLI applications require a way to understand how you want them to execute. This might include what files to read, what servers to contact, and what credentials to use.
There are a couple of ways to start an application with the parameters it requires:
- Using the
flag
package to define command-line flags - Using
os.Args
to read arguments that are not defined
The flag
package will help you when you have a command-line argument that has a strict definition. This might be an argument that defines the endpoint for a needed service. The program might want to have a default value for production , but allow an override when doing testing. This is perfect for a flag.
An example might be a program that queries our Quote of the Day (QOTD) server that we created earlier. We might want to have it automatically use our production endpoint unless we specify it to use another address. This might look like this:
qotd
This simply contacts our...