Golang flag.Lookup() function example
package flag
Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.
Golang flag.Lookup() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
verbose := flag.String("verbose", "on", "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 on}
on
Reference :
Advertisement
Something interesting
Tutorials
+9.3k Golang : How to protect your source code from client, hosting company or hacker?
+9.4k Golang : Web(Javascript) to server-side websocket example
+19.2k Golang : Check if directory exist and create if does not exist
+24k Golang : Find biggest/largest number in array
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+21.2k Golang : Clean up null characters from input data
+41.4k Golang : Convert string to array/slice
+9.3k Golang : Temperatures conversion example
+13.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+14.1k Javascript : Prompt confirmation before exit
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running