Go Lang Notes
Filesystem
Packages
path/filepath — filepath functions
os — main os functions
flag — used to get passed flags/parameters/arguments
How to collect passed flags/parameters/arguments to the GO program
- import the
flag Package ie.
import "flag"
- use the
flag.Arg function to get the non-flag arguments in the form of a string ie.
firstArgument := flag.Arg(0)
- use the
flag.Parse() to flags (have a dash) like: -d
- this sets the flags to their non-default values
flag.Bool — sets a boolean flag
flag.String — sets a string flag
- take three arguments: name of the flag, default value for the flag, and a help message or error message that will print if flag errors.
var b = flag.Bool("b", false, "some help string")
var myString = flag.String("my string", " default my string", "some help string for myString")