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
+7k Golang : Find the shortest line of text example
+11.3k Golang : How to flush a channel before the end of program?
+30.6k Golang : Remove characters from string example
+11.2k CodeIgniter : How to check if a session exist in PHP?
+5.6k PHP : Fix Call to undefined function curl_init() error
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+11.7k Golang : Secure file deletion with wipe example
+23.1k Golang : Randomly pick an item from a slice/array example
+19.1k Mac OSX : Homebrew and Golang
+14k Golang : concatenate(combine) strings
+10.4k Golang : Meaning of omitempty in struct's field tag
+9.7k PHP : Get coordinates latitude/longitude from string