Check if Flag Was Provided in Go
<p>With the flag package, is there a good way to distinguish if a string flag was passed?</p>

<p>For example, when the flag is not passed, I want to set it to a dynamic default value.  However, I want to set it to empty if the flag was provided but with a value of <code>""</code>.</p>

<p>Current I am doing the following:</p>

<pre><code>flagHost = flag.String(flagHostFlagKey, "", "...")
...
setHostname := false
for _, arg := range os.Args {
    if arg == "-"+flagHostFlagKey {
        setHostname = true
    }
}

if !setHostname {
     ...
</code></pre>

<p>Which seems to work fine, but is kind of ugly. Is there a better way while staying with the standard flag package?</p>