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
+8.3k Swift : Convert (cast) Character to Integer?
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+7.5k Golang : Process json data with Jason package
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+6.9k Golang : Pat multiplexer routing example
+8.4k Golang : Convert word to its plural form example
+9.9k Golang : Check if user agent is a robot or crawler example
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+6.9k Android Studio : Hello World example
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+20.6k Golang : Secure(TLS) connection between server and client