Golang flag.Flag type example
package flag
A Flag represents the state of a flag.
type Flag struct {
Name string // name as it appears on command line
Usage string // help message
Value Value // value as set
DefValue string // default value (as text); for usage message
}
Golang flag.Flag type 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
}
Output :
&{verbose Turn verbose mode on or off. on on}
Break down to :
Name = verbose
Usage = Turn verbose mode on or off
Value = on
DefValue = on
Reference :
Advertisement
Something interesting
Tutorials
+12.6k Golang : zlib compress file example
+22.3k Golang : How to read JPG(JPEG), GIF and PNG files ?
+10.8k Golang : Sieve of Eratosthenes algorithm
+17.5k Golang : Defer function inside init()
+8.8k Golang : Populate or initialize struct with values example
+7.7k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+16.3k CodeIgniter/PHP : Create directory if does not exist example
+21.6k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+13.6k Golang : Check if an integer is negative or positive
+16.7k Golang : How to generate QR codes?
+31.9k Golang : Validate email address with regular expression
+8.5k Golang : Set or add headers for many or different handlers