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
+22.9k Golang : Gorilla mux routing example
+6.3k Golang : How to get capacity of a slice or array?
+15.3k Golang : Get query string value on a POST request
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+5.2k Golang : Issue HTTP commands to server and port example
+9k Golang : Capture text return from exec function example
+7.5k Golang : How to stop user from directly running an executable file?
+10k Golang : Convert octal value to string to deal with leading zero problem
+5.7k Linux/Unix/PHP : Restart PHP-FPM
+40.1k Golang : UDP client server read write example
+10.6k Golang : Simple File Server