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
+9.2k Golang : Create and shuffle deck of cards example
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+24.6k Golang : How to validate URL the right way
+16.8k Golang : read gzipped http response
+4.7k Linux/MacOSX : How to symlink a file?
+13.4k Golang : Generate Code128 barcode
+5.9k Golang : Detect variable or constant type
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+8.5k PHP : How to parse ElasticSearch JSON ?
+10.7k Golang : Get currencies exchange rates example
+12.3k Golang : Display list of countries and ISO codes
+5.7k Get website traffic ranking with Similar Web or Alexa