Golang flag.String() function example
package flag
String defines a string flag with specified name(1st parameter), default value (2nd parameter), and usage string(3rd parameter). The return value is the address of a string variable that stores the value of the flag.
Golang flag.String() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
verbose := flag.String("verbose", "on | off", "Turn verbose mode on or off.")
flag.Parse()
fmt.Println(flag.Lookup("verbose")) // print the Flag struct
fmt.Println(*verbose)
}
Output :
&{verbose Turn verbose mode on or off. on | off on | off}
on | off
Reference :
Advertisement
Something interesting
Tutorials
+5.3k Swift : Convert string array to array example
+10.9k Golang : Sieve of Eratosthenes algorithm
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+11.1k Golang : Roll the dice example
+27.6k PHP : Convert(cast) string to bigInt
+17.8k Golang : Defer function inside init()
+35.9k Golang : Integer is between a range
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+10.5k Golang : Create matrix with Gonum Matrix package example
+20.8k Golang : Convert date string to variants of time.Time type examples
+36.5k Golang : Save image to PNG, JPEG or GIF format.