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
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+8.5k Golang : How to check if input string is a word?
+10.6k Golang : How to delete element(data) from map ?
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+14.3k Golang : Simple word wrap or line breaking example
+13.6k Golang : Strings comparison
+6.4k PHP : Proper way to get UTF-8 character or string length
+10.6k Golang : Select region of interest with mouse click and crop from image
+6k PHP : How to check if an array is empty ?
+13k Swift : Convert (cast) Int to String ?
+8.3k Golang : Auto-generate reply email with text/template package