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
+17.5k Golang : Clone with pointer and modify value
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+25.3k Golang : Convert uint value to string type
+16.6k Golang : Delete files by extension
+6.1k Golang : Debug with Godebug
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+8.8k Golang : Take screen shot of browser with JQuery example
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+36k Golang : Get file last modified date and time
+5.6k Golang : Shortening import identifier
+10.3k Golang : Detect number of faces or vehicles in a photo