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
+5.4k Golang : Reclaim memory occupied by make() example
+21.1k Golang : For loop continue,break and range
+18.4k Golang : How to remove certain lines from a file
+13.4k Golang : Generate Code128 barcode
+13.2k Golang : Convert(cast) int to int64
+10.1k Golang : How to get quoted string into another string?
+13.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+14.4k Android Studio : Use image as AlertDialog title with custom layout example
+8.1k Golang : Randomize letters from a string example
+15.2k Golang : Accurate and reliable decimal calculations