Golang flag.Value type examples
package flag
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)
If a Value has an IsBoolFlag() bool method returning true, the command-line parser makes -name equivalent to -name=true rather than using the next command-line argument.
Golang flag.Value type usage examples
func lookupStringSlice(name string, set *flag.FlagSet) []string {
f := set.Lookup(name)
if f != nil {
return (f.Value.(*StringSlice)).Value()
}
return nil
}
func lookupIntSlice(name string, set *flag.FlagSet) []int {
f := set.Lookup(name)
if f != nil {
return (f.Value.(*IntSlice)).Value()
}
return nil
}
func lookupGeneric(name string, set *flag.FlagSet) interface{} {
f := set.Lookup(name)
if f != nil {
return f.Value
}
return nil
}
func lookupBool(name string, set *flag.FlagSet) bool {
f := set.Lookup(name)
if f != nil {
val, err := strconv.ParseBool(f.Value.String())
if err != nil {
return false
}
return val
}
return false
}
Reference :
Advertisement
Something interesting
Tutorials
+29.3k Golang : Save map/struct to JSON or XML file
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.3k Golang : How to iterate a slice without using for loop?
+11.9k Golang : Determine if time variables have same calendar day
+16.9k Golang : How to generate QR codes?
+18.6k Golang : Get download file size
+15.9k Golang : Read a file line by line
+15.8k Golang : How to login and logout with JWT example
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+16.1k Golang : How to check if input from os.Args is integer?
+28.8k Golang : Detect (OS) Operating System
+19.8k Golang : Append content to a file