...

/

Accessing Non-Flag Arguments

Accessing Non-Flag Arguments

Learn about arguments and how to access non-flag arguments in Go.

We'll cover the following...

Arguments in Go are read in a few ways. We can read the raw arguments using os.Args, which will also include all the flags. This is great when no flags are used.

When using flags, flag.Args() can be used to retrieve only the non-flag arguments. If we want to send a list of authors to a development server and retrieve QOTDs for each author, the command might look like this:

Press + to interact
qotd --dev "abraham lincoln" "martin king" "mark twain"

In this list, we use a --dev flag to indicate that we want to use the development server. Following our flag, we have a list of ...